retrive clicked marker info?

2,972 views
Skip to first unread message

Thoern

unread,
Mar 28, 2011, 7:06:44 AM3/28/11
to Google Maps JavaScript API v3
I have a array with markers but how do I get what index the clicked
marker have?
of one click on one of the markers in the map.

geoco...@gmail.com

unread,
Mar 28, 2011, 9:31:16 AM3/28/11
to Google Maps JavaScript API v3
Hard to say without a link to your map.
You could use function closure or add a property to the marker.

-- Larry

Thoern

unread,
Mar 28, 2011, 10:30:42 AM3/28/11
to Google Maps JavaScript API v3
Its really like a basic tutorial example, storing the markers in a
locations array, no funny buissness to it.
http://www.chalmersmotorklubb.se/google/Example.htm



Thoern

unread,
Mar 28, 2011, 10:33:43 AM3/28/11
to Google Maps JavaScript API v3
Is there some call or so in the API to check which index is selected
once clicking a marker?

geoco...@gmail.com

unread,
Mar 28, 2011, 11:08:43 AM3/28/11
to Google Maps JavaScript API v3
On Mar 28, 7:33 am, Thoern <turbokil...@gmail.com> wrote:
> Is there some call or so in the API to check which index is selected
> once clicking a marker?

There is no API call to do that. You can store that information as a
property of the marker as I suggested in my original answer:

marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][2], locations[i][3]),
map: map });
marker.myMarkerIndex = i;
...

The best answer to your question will depend on _why_ you want that
information and what you need it for.

-- Larry
-- Larry

JKurtock

unread,
Mar 28, 2011, 1:45:30 PM3/28/11
to Google Maps JavaScript API v3
Did you resolve your issue? It (now) looks like you are using a
function closure (good choice!).

- jeff

Thoern

unread,
Mar 29, 2011, 4:20:03 AM3/29/11
to Google Maps JavaScript API v3
Anyhow I thought of a different approach, googlemaps does only render
the markers in current mapwindow right? can you fetch those array ids
somehow ? or the coordinates of the markers?


I would like to get the markers id for two purposes. (both ways)

1. to do some extra stuff (maby open a certain kml file) based on the
map clicked markers id.
2 have the marker "highligted" when doing a seach on one of the
markers so you can see wich one you picked in select/option list.

Chris Broadfoot

unread,
Mar 29, 2011, 4:49:49 AM3/29/11
to google-map...@googlegroups.com, Thoern
You can reference the clicked marker with 'this':

google.maps.event.addListener(marker, 'click', markerListener);

function markerListener() {
  alert(this.getPosition());
  // this.setIcon(...
}


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.




--
http://twitter.com/broady

Thoern

unread,
Mar 29, 2011, 5:29:48 AM3/29/11
to Google Maps JavaScript API v3
Thanks, there it was :-)

Any Ideas to check which markers in current mapview?

Chris Broadfoot

unread,
Mar 29, 2011, 5:44:59 AM3/29/11
to google-map...@googlegroups.com, Thoern
No, you'll need to store that yourself. Trivial to do.

Thoern

unread,
Mar 29, 2011, 7:54:57 AM3/29/11
to Google Maps JavaScript API v3
Ok, I am kind of stuck here, it seems markers have a method
getVisible() that sounds usable for this purpose, anyhow tried to feed
it som indexes from the marker array in 'bounds_changed' event

Had hoped to get info like:
1 true
2 false
3 false

sombody please point me in the right direction
cant find any info about how to use the marker.getVisible();
or is that for all the markers, not for one instance of the marker ie
maker(i).getVisible();

Thoern

unread,
Mar 30, 2011, 1:48:08 AM3/30/11
to Google Maps JavaScript API v3
Solved..
Reply all
Reply to author
Forward
0 new messages