Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain the HTML DOM element of a Google Maps marker?

Given a GMarker JS variable, how do I obtain the HTML DOM element that represents it? I need this so I can insert a <div> of my own into the map with the correct z-index.

Thanks.

like image 636
Aistina Avatar asked Aug 05 '09 12:08

Aistina


1 Answers

Sorry to post on such an old question, but I've just come across this myself. The solution I used in Google Maps APIv3 was to copy the "Custom Marker" from the Google Maps samples and add a simple method getDOMElement, which returns the div generated in the Marker's construction.

CustomMarker.prototype.getDOMElement = function() {
  return this.div_;
}

You can then use marker.getDOMElement().style to dynamically change the styling of your marker, and the img child element of marker.getDOMElement() is the icon used, so you can change that dynamically too.

like image 129
SubmittedDenied Avatar answered Nov 10 '22 16:11

SubmittedDenied