【发布时间】:2020-10-21 06:23:41
【问题描述】:
我知道这个问题与很多其他问题相似。
以下问题。我用数组保存 Google 地图标记。
如果我想更新它们,我无法编写 marker.set(Something)。我必须写 marker.j.map = null;
- 我错过了什么吗?
例如
var markers = [];
function doAddMarkers(){
markers.push(new google.maps.Marker({
[...]
}).addListener('click', (function (i) {
[...]
}).bind(this, "xxx"), false));
}
function DoStartHl(pElement) {
for (var i = 0; i < markers.length; i++) {
if (pElement !== i && markers[i].j.animation !== null) {
markers[i].j.animation = null;
}
}
if (markers[parseInt(pElement.id)].j.animation === null) {
markers[parseInt(pElement.id)].j.animation = google.maps.Animation.BOUNCE;
}
}
解决方法是在当前标记和setter之间添加.j.。
【问题讨论】:
-
您正在使用索引遍历标记数组。所以,
marker没有定义。您应该通过标记数组中的索引来引用标记... -
请提供一个 minimal reproducible example 来证明您的问题,最好是 StackOverflow 代码 sn-p。
-
@geocodezip 现在好看了吗?
标签: javascript google-maps google-maps-api-3 maps