Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger the onClick event of a marker on a Google Maps V2 for Android?

Is there a way of calling onClick event of a specific marker manually (without physically tapping the marker)?

like image 228
mustafa Avatar asked Apr 22 '15 14:04

mustafa


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 you refresh a marker on Google Maps?

To reload the markers, when you create then, push them to an array. Then create a function where you iterate through the array, setting the markers map as null. After this, erase the array.


1 Answers

No, but you can simulate the onClick event. 2 things happen when you click a marker:

  1. The info window for the corresponding clicked marker is shown.
  2. The camera pans to the marker.

The above can be achieved with 2 lines of code:

marker.showInfoWindow();
map.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()), 250, null);
like image 189
iflp Avatar answered Sep 22 '22 08:09

iflp