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

后端 未结 3 1052
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 02:07

Given a GMarker JS variable, how do I obtain the HTML DOM element that represents it? I need this so I can insert a

of my own into the map with the
3条回答
  •  孤城傲影
    2021-01-06 02:39

    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.

提交回复
热议问题