【发布时间】:2023-03-12 23:26:01
【问题描述】:
我正在尝试将标记绑定到多边形的顶点,这样移动标记会改变多边形的形状。
var polygonLine = new google.maps.Polyline(
{
path: [],
map: map,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
polygonLine.getPath().push(new google.maps.LatLng(-31.95202, 115.8548));
polygonLine.getPath().push(new google.maps.LatLng(-31.94980, 115.8586));
polygonLine.getPath().push(new google.maps.LatLng(-31.95246, 115.8625));
polygonLine.getPath().push(new google.maps.LatLng(-31.95508, 115.8558));
var polygon = new google.maps.Polygon({map: map, path: polygonLine.getPath()});
var vertices = polygon.getPath();
for (var i = 0; i < vertices.getLength(); i++)
{
markers[i] = new google.maps.Marker({ position:vertices.getAt(i), map: map, draggable: true });
vertices.getAt(i).bindTo('position', markers[i], 'position'); // Throws an error
}
现在这不起作用,因为在最后一行的第 2 行,vertices.getAt(i) 返回一个 LatLng,它不支持 'position' 属性。
有谁知道我如何将标记绑定到顶点?谢谢:)
【问题讨论】:
标签: javascript binding google-maps-api-3 google-maps-markers