Efficient Map Overlays in Android Google Map

后端 未结 5 1318
北恋
北恋 2020-12-04 07:50

I want to do the following and am kind of stuck on these for a few days:

  1. I was trying to draw polylines (I have encoded polylines, but have

5条回答
  •  温柔的废话
    2020-12-04 08:05

    I have the same problem. We are developing an iphone app and an android app at the same time. I have 2500 + map overlays. No problem on iphone; a huge performance hit on android when calling populate() after adding all overlays. (Of course, my first try was to call populate() every time after adding an overlay; a typical mistake due to google's tutorial. Now I am calling populate() just once, after all 2500+ overlays have been added to the ItemizedOverlay.)

    So the single populate() call takes over 40 seconds to complete on an htc hero device. I had to put in a busy indicator; no progress bar is possible because we cannot get any information about the progress of populate().

    I tried another solution: not use ItemizedOverlay but add overlays by hand, subclassing Overlay. Result: indeed it is much faster to add all those overlays to the map; however, the map becomes unusable due to constant calling of the draw() method on each overlay. In my draw method, I tried to optimize as much as possible; I do not create a bitmap every time. My draw() method looks like this:

    public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)  {
    // our marker bitmap already includes shadow.
    // centerPoint is the geopoint where we need to put the marker.
     if (!shadow) {
      Point point = new Point();  
      mapView.getProjection().toPixels(centerPoint, point);
      canvas.drawBitmap(markerBitmap, point.x, point.y, null);
     }
    
    }
    

    Here markerBitmap is precomputed. I don't know what else I could optimize. Is there some kind of populate() call required if we are not using ItemizedOverlay??? I could not find any good answers for that.

    Right now I resort to caching the ItemizedOverlay once it has been created in a background thread. This way at least the user does not have to wait every time.

提交回复
热议问题