我有一个脚本,可以将标记一一添加到地图
var marker = new google.maps.Marker({
position: new google.maps.LatLng(51,-117)
});
marker.setIcon(getIconFile(initialIconId));
markers.push(new Array(id,marker)); // id, marker
marker.setMap(map);
稍后在脚本中,当我按下自定义按钮时,我希望能够更改标记图标。因此,我通过标记数组中的 id 获取标记并调用:
markers[markerIndex].setIcon(getIconFile(newIconId)); // which returns a string url of the icon
但是我收到:TypeError: markers[markerId].setIcon is not a function
我打印了 markerId 并且它是有效的,我还打印了标记标记 [markerId] 的索引结果,它返回一个标记对象。我没有其他方法可以调试这个我迷路了!
谢谢