0
我試圖將標記綁定到多邊形的頂點,以便移動標記將更改多邊形的形狀。Google Maps Api V3:如何將標記綁定到多邊形的頂點?
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)返回一個經緯度,不支持「位置」屬性。
有誰知道我怎麼可能會在標記綁定到頂點?謝謝:)