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 week, i've noticed when i went onto my app that loading the 400 markers to the map took about 10-20 seconds on my Galaxy S5 and that there is a small circle in the middle of the default map marker icons. Before this, the map loaded in less than a second. I haven't updated or changed my app. I'm guessing Google updated the Google Map API and the change made it much slower to load markers? Has this happened to anyone else? Does anyone else have information about this?
My app is available for free on the Play Store. You can search NYS Canal Guide to find it if you want to see how slow it loads.
This method gets called in the onCreateView() of the map fragment after the map is initialized:
private void addExistingMarkersToMap(){
log("Adding existing markers to the map. poiAdapter size = " + poiAdapter.getCount());
Marker marker;
MarkerOptions markerOptions;
for(MapMarker mapMarker : poiAdapter){
if(markersNotFilteredOut(mapMarker)){
markerOptions = mapMarker.getMarkerOptions();
if(markerOptions != null && mapMarker != null){
marker = mMap.addMarker(markerOptions);
mapMarker.setMarker(marker);
}
}
}
}
This is the getMarkerOptions() method on a MapMarker class:
public MarkerOptions getMarkerOptions() {
return new MarkerOptions()
.title(name)
.position(new LatLng(lat, lng))
.snippet(bodyOfWater + ", mile " + mile)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
}
The full source code is here: github.com/olearyj234/NYS-Canal-Guide
EDIT:
** To be specific, the only part that is slow is loading the markers when the map is being initialized(so also when switching from one navigation tab and back to the map tab). It isn't slow when moving the map or anything else.
Here are some logs that come up:
While the screen is frozen for a few seconds(5-15) because its loading the markers, this log is being produced very fast. The bitmap id continues to increment by one and while the markers are loading, it produces about 400 of these logs. This shows that it has to be a problem related to loading the marker bitmaps on the screen. I'm using the default marker bitmap.
10-01 15:45:07.222: D/skia(32108): GFXPNG PNG bitmap created width:16 height:32 bitmap id is 414
This log is produced when the app is finished loading all the markers to the map.
10-01 15:51:09.402: I/Choreographer(8353): Skipped 1130 frames! The application may be doing too much work on its main thread.
This log is produced 14 times when the app is finished loading all the markers to the map.
10-01 15:59:13.882: I/dalvikvm-heap(8353): Grow heap (frag case) to 40.668MB for 4194320-byte allocation
EDIT 2:
I just checked to see how long it would take for certain lines of code. I used System.currentTimeMillis();
in order to get times. In the method addExistingMarkersToMap()
, this is the line that took long: marker = mMap.addMarker(markerOptions);
When adding all 400 markers, it took 54 ms on average for each marker. The min time was 34ms and the max was 114ms.
If there's any more information you think i should provide, let me know in a comment. Thank you!