apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.26k stars 382 forks source link

open marker with external link? #254

Closed opetznick closed 12 years ago

opetznick commented 12 years ago

hello

i was wondering if its possible to trigger the open infowindow event on the marker using a js function?

something like:

<a href="javascript:void(0);" onclick="Gmaps.map.map.panTo(mymarker)">Show me my marker</a>

is there a way to get the mymarker object with gmaps4rails?

thanks in advance oliver

apneadiving commented 12 years ago

Markers are stored in Gmaps.map.markers, so one marker is var myMarker = Gmaps.map.markers[i];

If you want the google or whatever provider marker object: myMarker.serviceObject.

You end up with:

<a href="javascript:void(0);" onclick="Gmaps.map.serviceObject.panTo(Gmaps.map.markers[i].serviceObject)">Show me my marker</a>

But you have to tell what is i.

Sidenote, in the next version of gmaps4rails, the api will change a bit. Beware when you update.

marcel12bell commented 10 years ago

@apneadiving Thanks for the Sidenote... I updated to V2 and now my markers don't open. how can I access them to open? I searched a lot, but found no solution...