我绘制折线如下:
var data = JSON.parse(data);
var LineCordinates = new Array();
for (i=0; i<data.length; i++){
LineCordinates[i] = new google.maps.LatLng(data[i].fields.latitude, data[i].fields.longitude);
}
linePath = new google.maps.Polyline({
path: LineCordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
linePath.setMap(map);
}
我想在多边形线的marker
和polygon line
的开头放置一个end
。怎么做?
答案 0 :(得分:3)
var startMarker = new google.maps.Marker({
position:linepath.getPath().getAt(0),
map:map
});
var endMarker = new google.maps.Marker({
position:linepath.getPath().getAt(linepath.getPath().getLength()-1),
map:map
});
答案 1 :(得分:0)
由于您在LineCordinates
中保持折线的坐标,因此您可以使用其第一个和最后一个元素作为标记的参考:
...
linePath.setMap(map);
var marker1 = new google.maps.Marker({
position: LineCordinates[0],
map: map,
title: "Start"
});
var marker2 = new google.maps.Marker({
position: LineCordinates[ LineCordinates.length - 1 ],
map: map,
title: "End"
});
...