Getting a map marker by its ID in Google Maps v2

后端 未结 5 1681
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-25 14:06

basically when adding a marker to the map it returns the new marker and you can gets the marker id from it like so

Marker m = map.addMarker(new MarkerOptions         


        
5条回答
  •  甜味超标
    2020-12-25 14:54

    Use WeakHashMap to store markers because in this way, we wouldn't keep a reference to a Marker in memory, and wouldn't have to worry about garbage collected markers.

    secondly recommended way to do this is to have a WeakHashMap with ID and your custom data. The documentation says that marker object may change, so don't use the marker as the key. if the activity is killed and restored but the ID will remain the same. sometime it may return null also if marker objects changed.

    WeakHashMap obj = new WeakHashMap ();
    

    Hope it will help future viewers...

提交回复
热议问题