最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I get the HTML of a Google maps marker? - Stack Overflow

programmeradmin0浏览0评论

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...

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...

Share Improve this question edited Aug 1, 2010 at 23:39 Brock Adams 93.7k23 gold badges241 silver badges305 bronze badges asked Jul 30, 2010 at 13:44 AHOYAHOYAHOYAHOY 1,8674 gold badges24 silver badges36 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6 +100

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 (i.e. mysite./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.

发布评论

评论列表(0)

  1. 暂无评论