2

I'm developing an application that's tracing lines of highways on the Google Maps SDK Add-On.

There are a lot of points painted, which inadvertently make the Maps very sluggish to navigate. It seems iOS Maps take care of this issue, as a significant amount of points can be drawn without the maps becoming sluggish.

I started sampling points depending on zoom level. E.g. zoom level 7 only uses, and draws lines to, every 20th point to trace the route. But even that is still too many points and ends up with a very sluggish panning and zooming experience.

Two questions:

One: Is it possible to detect the current region of the map being displayed in the phone, and no longer paint points off-screen?

EDIT - after some initial investigation it's easily possible to detect the clipping region and not paint points/lines. quickReject is the function I've used for this. It does not help too much with performance as all points are still being traversed to identify if they must be drawn - I'm sure it can be optimized.

Two: Is it at all possible to cache, perhaps the path, being drawn (this would have to be done per zoom level, I assume, due to the projection of the point?)

jlindenbaum
  • 1,891
  • 18
  • 28

1 Answers1

1

Is it possible to detect the current region of the map being displayed in the phone, and no longer paint points off-screen?

Yes, you can get the projection of the four corners of your screen :

Projection proj = mapView.getProjection();
GeoPoint topLeft = proj.fromPixels(0, 0);

GeoPoint bottomRight = proj.fromPixels(mapView.getWidth()-1, mapView.getHeight()-1);

double topLat = topLeft.getLatitudeE6()/1E6;
double topLon = topLeft.getLongitudeE6()/1E6;
double bottomLat = bottomRight.getLatitudeE6()/1E6;
double bottomLon = bottomRight.getLongitudeE6()/1E6;

While rendering, you should only select points that lie in these bounds.

See also :

In case you are at a very high zoom level see:

Personally I've use route simplification algorithms to reduce the number of points on a straight path. For e.g if 20 points lie in the same line, it makes sense to use the start and end point and drawn a straight line.

Community
  • 1
  • 1
Reno
  • 33,594
  • 11
  • 89
  • 102
  • Thanks! The populate is something I can use. The problem is these are not markers, but points that end in lines - Lines that are longer than the screen. So it's very likely that, on the line drawn, both the start and end point are off screen, but the line between is on screen. Still have to traverse all those points to see if they must be drawn or not. – jlindenbaum Nov 10 '11 at 16:28
  • I think you should [profile your code](http://developer.android.com/guide/developing/debugging/debugging-tracing.html) to see which methods are taking most of the time. You will know exactly where you need to optimize :) – Reno Nov 10 '11 at 16:43