{"id":462,"date":"2010-08-26T07:01:20","date_gmt":"2010-08-26T07:01:20","guid":{"rendered":"http:\/\/www.nickbennett.co.uk\/?p=462"},"modified":"2025-06-11T15:48:21","modified_gmt":"2025-06-11T15:48:21","slug":"google-marker-events","status":"publish","type":"post","link":"https:\/\/blog.nickbennett.co.uk\/index.php\/2010\/08\/26\/google-marker-events\/","title":{"rendered":"Google Marker Events"},"content":{"rendered":"<p>My latest project involves using google maps. So far I&#8217;ve been very impressed with the API. There are plenty of examples and explanations of how everything works. However, I came across a problem that seemed like a common enough scenario yet the answer could not be found. Eventually, I found this <a title=\"Google Marker Solution\" href=\"http:\/\/you.arenot.me\/2010\/06\/29\/google-maps-api-v3-0-multiple-markers-multiple-infowindows\/\" target=\"_blank\" rel=\"noopener\">post<\/a> which helped point me in the right direction.<\/p>\n<p>I had a similar problem where I had an array of longitudes and latitudes that all required their own events. For each marker, I needed a mouseover and mouseout click function. Again the issue was that the last array items were the values being used regardless of which marker&#8217;s event is fired. I needed a way to identify which marker the event was applicable to. The solution was found by using the &#8216;this&#8217; variable within the event function. From &#8216;this&#8217; you can use the this.position.c\u00a0 to find the longitude and the this.position.b to find the latitude of that particular marker. Hope this helps!<\/p>\n<pre>\n  <code>\n\/\/ Loop through our list of longs and lats\nfor (i=0;i&lt;initialMarkerHolder.length;i++) {\n\tgoogle.maps.event.addListener(marker, 'click',function() {\n\t\talert('log = ' + this.position.c);\n\t\talert('lat = ' + this.position.b);\n\t});\n}\n<\/code>\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>My latest project involves using google maps. So far I&#8217;ve been very impressed with the API. There are plenty of examples and explanations of how everything works. However, I came across a problem that seemed like a common enough scenario yet the answer could not be found. Eventually, I found this post which helped point [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":373,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[38,151,192,200,245,264,277,278],"class_list":["post-462","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripts","tag-api","tag-event","tag-google","tag-handler","tag-latitude","tag-longitude","tag-maps","tag-marker"],"_links":{"self":[{"href":"https:\/\/blog.nickbennett.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nickbennett.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nickbennett.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nickbennett.co.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nickbennett.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=462"}],"version-history":[{"count":2,"href":"https:\/\/blog.nickbennett.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/462\/revisions"}],"predecessor-version":[{"id":1448,"href":"https:\/\/blog.nickbennett.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/462\/revisions\/1448"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.nickbennett.co.uk\/index.php\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/blog.nickbennett.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nickbennett.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nickbennett.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}