Skip to content Skip to sidebar Skip to footer

Android Google Map Addmarker() Very Slow When Adding 400 Markers

Thank you for taking the time to read this. I published an app to the Google Play store about a month ago(08/29/14) and this wasn't a problem with the same amount of markers. This

Solution 1:

This appears to be a new problem introduced in Google Maps API v2 (looks like one of the Play Services 6 updates), see #7174 for more info (and please star it).

From the info provided in the issue, the problem seems to be specific to using a default marker with a hue, e.g.:

BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)

There are some workarounds. Easiest is to not provide a hue (if all your markers being red is acceptable):

BitmapDescriptorFactory.defaultMarker()

Or use custom drawables:

BitmapDescriptorFactory.fromResource(R.drawable.map_marker)

I see a ~2000 times slowdown when using the default marker with a hue. I'm going with the custom drawables as a solution for now.

Solution 2:

It is my understanding that each time you draw a marker it sends the drawing operations to a thread pool in the background while it returns the marker. It is easy to overwhelm the CPU by flooding the request through too quickly. Use the handler from the main looper and and post delayed at increasing intervals to spread out the operations as in the code below.

Handlerhandler=newHandler(Looper.getMainLooper());
intx=0;
longDELAY=10;
for(MapMarker mapMarker : poiAdapter){
    if(markersNotFilteredOut(mapMarker)){
        markerOptions = mapMarker.getMarkerOptions();

        if(markerOptions != null && mapMarker != null){
           handler.postDelayed(
                   newRunnable() {
                      @Overridepublicvoidrun() {
                          marker = mMap.addMarker(markerOptions);
                          mapMarker.setMarker(marker);
                      }
                   }, (DELAY * (long)x++));
        }
    }
}

Post a Comment for "Android Google Map Addmarker() Very Slow When Adding 400 Markers"