How to know which Marker was clicked on Google Maps v2 for Android?

前端 未结 5 2146
挽巷
挽巷 2020-12-09 20:15

I am making an application with a Google Maps on it, for Android. I have plenty of Markers on my screen and I am preparing customizable balloon for each marker when they are

5条回答
  •  醉话见心
    2020-12-09 20:32

    You are not obligated to show title when you have it set, so you can use that and as long as you return a View from getInfoContents and not setText on any subview of that returned View with title value.

    Depending on how and if you already keep references to all markers, there are alternatives, e.g. if you had List policeMarkers and List badGuysMarkers you can use a conditional if (policeMarkers.contains(marker)) { ... } else { ... }.

    You can also keep a Map allMarkers and do YourMarkerRelatedDataModel model = allMarkers.get(marker); and use that value to differentiate.

    Finally you can use Android Maps Extensions, which adds functions like Marker.setData(Object) and Object Marker.getData() to keep your model close to your markers and not create things like Map.

提交回复
热议问题