Reputation: 6046
Hi I'm using google android maps v2 and adding a bunch of markers to the map however I need to add additional data to the marker objects for recall later in the onInfoWindowClick function.
I currently have a MarkerManager singleton class which maintains a concurrent list of venues however inside the onInfoWindowClick function I need to recall this via some form of key from the MarkerManager.
It appears that markers are static final and can't be extended so I'm a bit stuck on how to do this.
thanks,
Andy
Upvotes: 2
Views: 3104
Reputation: 45942
You can create a HashMap:
Map<Marker, YourCustomObject> theMap;
Then add the markers as keys:
Marker m = mMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.whatever)).position(new LatLng(mLat, mLong)));
theMap.put(m, yourCustomObjectInstance);
Finally in your Info Window provider, you can retrieve your object via the marker supplied to the getInfoWindow
function`:
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
YourCustomObject yourCustomObjectInstance = theMap.get(marker);
}
Upvotes: 16