20

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.

Guru
  • 867
  • 3
  • 11
  • 21
  • Most of the answers given where about catching a click event on a marker. To clarify, do you mean like simulating a click on a certain marker instead of listening to the event? – vida Apr 18 '13 at 09:50
  • Yes, I want to simulate a click on marker. I know how to listen to the marker click events. – Guru Apr 19 '13 at 14:47
  • I have the same problem. There's no API for that as of now. I've tried to figure out what could be a possible work around but I don't think it's doable as of the moment because of the API limitations. – vida Apr 22 '13 at 02:49

3 Answers3

21

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.

MaciejGórski
  • 21,800
  • 7
  • 67
  • 92
  • Hmm, do you mean to say that I will not be able to trigger a marker click through my code ? I understand how to use a marker click listener (I am actually using it my code), but I wanted to trigger the click through my code without having to touch/click on the marker. – Guru Apr 17 '13 at 14:58
  • I gave you a workaround. There is no such method Marker.doClick(), but you can call OnMarkerClickListener's method yourself without direct interaction with the library. – MaciejGórski Apr 17 '13 at 15:36
  • 1
    Btw. you may want to submit a feature request here: [gmaps-api-issues](http://code.google.com/p/gmaps-api-issues/issues/list?can=2&q=apitype%3DAndroid2) or here: [Android Maps Extensions](http://code.google.com/p/android-maps-extensions/) (or both). – MaciejGórski Apr 17 '13 at 15:50
  • hi this works but i would like to show navigate buttons in onmarkerclick – David Feb 28 '17 at 08:59
2

There is a good tutorial for detecting a marker click on Google maps V2 here: http://android-er.blogspot.in/2013/01/google-maps-android-api-v2-example_5213.html

Hope this will helps you.

Felipe
  • 15,458
  • 9
  • 63
  • 87
Amol Sawant 96 Kuli
  • 11,212
  • 2
  • 18
  • 27
-2

OnMapClickListener is an Interface you can use to detect clicks on Google Maps V2. Kind of a "trigger" like in js. You set a Listener for specific events and you wait until you got some. Then you declare a method and you handle the event.

t0s
  • 1,101
  • 5
  • 18
  • 27