本文介绍了如何在 google-maps-v3 上获取所有标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Google 地图上获取所有标记?

Is there a way to get all the markers on Google Maps?

推荐答案

如果您的意思是我如何才能获得对给定地图上所有标记的引用" - 那么我认为答案是抱歉,您必须这样做你自己".我认为没有任何方便的maps.getMarkers()"类型函数:在创建点时您必须保留自己的引用:

If you mean "how can I get a reference to all markers on a given map" - then I think the answer is "Sorry, you have to do it yourself". I don't think there is any handy "maps.getMarkers()" type function: you have to keep your own references as the points are created:

var allMarkers = [];
....
// Create some markers
for(var i = 0; i < 10; i++) {
    var marker = new google.maps.Marker({...});
    allMarkers.push(marker);
}
...

然后您可以遍历 allMarkers 数组并执行您需要执行的任何操作.

Then you can loop over the allMarkers array to and do whatever you need to do.

这篇关于如何在 google-maps-v3 上获取所有标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 04:19