Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triggering a map event (like a marker click) in Google maps Android V2

Tags:

I am trying to trigger a marker click (or other map events too) programmatically in Google maps API for android V2. Does anyone have an idea as to how to do it ?

Apparently javascript api (v3) , has a trigger function but I could'nt find anything for android.

Thanks for the help.

like image 547
Guru Avatar asked Apr 12 '13 15:04

Guru


People also ask

How do I add a marker to Google Maps Android?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.

How do I add an event to Google Maps?

To add an event, head to Google Maps on Android, tap on Contribute >Events > Add a public event. You can add an event name, tag the location, and add the time and date of the event as well. There's an option to add an image, write more event details, and add description as well.

Can you make markers in Google Maps?

Google Maps allows you to customize maps by adding markers manually or as a group.


1 Answers

You cannot triger a marker click directly.

If you need to run default implementation when onMarkerClick returns false (or you have no OnMarkerClickListener), you need to do it yourself:

marker.showInfoWindow();
map.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()), 250, null);

250 is assumed here, API doesn't give you the value used internally for this default marker click behaviour.

If you have a OnMarkerClickListener, you can just keep the reference and call a function on it sending marker as a param.

like image 142
MaciejGórski Avatar answered Oct 07 '22 21:10

MaciejGórski