简体   繁体   中英

How do I get the HTML of a Google maps marker?

How get HTML element from Google maps marker (v3)?

<div style="overflow-x: hidden; overflow-y: hidden; position: absolute; background-image: url(...); top: 62px; width: 70px; height: 70px; background-size:  ; left: 924px; z-index: 97; opacity: 0,01; cursor: pointer; background-position: 0px -420px; background-repeat: no-repeat no-repeat; " title=""></div>

Here is all markers map.getPanes().overlayImage; But I don't know which child is my marker...

You could assign a unique ID to the title attribute of each marker, and then search all markers until you find one with that ID

for (var marker in map.getPanes().overlayImage.getElementsByTagName("div")) {
  if (marker.title == "some_id") return marker;
}

As a last resort, you could also use a server side script to generate unique IDs client side for each image. Your server would return the same image (your marker icon) regardless of the filename (ie mysite.com/marker/De4gy.png). You can then crawl the DOM looking for DIVs that contain that URL in their style attributes. Note that this could hurt performance, as markers will no longer be cachable.

Note that changes to the way in which markers are added to the DOM by the API will likely break all of the above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM