0

I am using google map view and adding markers to it using this code:

googleMap.addMarker(new MarkerOptions()
.position(chargingStationObject.geoData)
.title(chargingStationObject.name)
.snippet(chargingStationObject.stationAvailability)
.data((chargingStationObject.id))
.icon(iconDescriptor));

iconDescriptor is created like this:

iconDescriptor = BitmapDescriptorFactory.fromResource(getResources()
     .getIdentifier("mapicon", "drawable", getActivity().getPackageName()));

When there are too many markers on my map, the heap is filled to its maximum, and after a while the app crashed with an out-of-memory-exception. This only happens when there are or have been a larger amount of markers on the map. Even after I call .clear(), the heap is still rather large.

Maybe the bitmaps haven't been recycled properly?

deimos1988
  • 5,896
  • 7
  • 41
  • 57

2 Answers2

0

Do on thing.

I assume, you are using same marker for all location.

Put the condition here

if(iconDescriptor==null){
            iconDescriptor = BitmapDescriptorFactory.fromResource(getResources().getIdentifier("mapicon", "drawable", getActivity().getPackageName()));
        }

Do not create new bitmap for every marker use just one copy for that and see what happens.

Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77
  • iconDescriptor = BitmapDescriptorFactory... is only called once at onCreate(), I already thought of that :) – deimos1988 May 09 '14 at 09:34
  • Then you must use clustering for that. – Biraj Zalavadia May 09 '14 at 09:35
  • Ok, but shouldn't it be possible to recycle those used Bitmaps once they are no longer shown on the map (I'm not sure that they are recycled, that's why I would like to initiate that process myself) – deimos1988 May 09 '14 at 14:35
0

for handle larger amount of markers on google map have to use Google Maps Android Marker Clustering Utility

For find more visit, https://developers.google.com/maps/documentation/android/utility/marker-clustering

Akash Moradiya
  • 3,318
  • 1
  • 14
  • 19