How to I make the markers in Android Google Maps API v2 become clickable so they will either bring up a menu with options or just start a new activity? I believe I made the markers in my app currently in a "newb" method. I didn't assign them a name or a method to be able to link it in with the rest of the required code.
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("My Spot")
.snippet("This is my spot!")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
If you ANSWER this, please include a sample code of a marker being introduced with a unique name and then being set as clickable to open a new activity.
Another Solution : you get the marker by its title
}
Avoid using Activity implements OnMarkerClickListener, use a local OnMarkerClickListener
You will need a map to lookup the original data model linked to the marker
You will need a data model
Put some data in the data model
When creating a new marker using a data model add both to the maker map
For on click marker event, use a local OnMarkerClickListener:
For displaying the info window retrieve the original data model from the marker map:
I have edited the given above example...
Here is my whole code of a map activity with 4 clickable markers. Click on a marker shows an info window, and after click on info window you are going to another activity: English, German, Spanish or Italian. If you want to use OnMarkerClickListener in spite of OnInfoWindowClickListener, you just have to swap this line:
to this:
this line:
to this:
and at the end of the method "onMarkerClick":
I think it may be helpful for someone ;)
All markers in Google Android Maps Api v2 are clickable. You don't need to set any additional properties to your marker. What you need to do - is to register marker click callback to your googleMap and handle click within callback:
here is a good guide on google about marker customization
setTag(position)
while adding marker to map.getTag()
onsetOnMarkerClickListener
listener