我有這個功能,點擊標記後,在與某個項目相關的點之間繪製一條線。Google Maps API V3 - 管理多段線
function showDetails(itemId)
{
var newlatlng = itemId.position;
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "index.php?r=items/ajaxdetails&id="+itemId.indice,
false);
xmlhttp.send();
var checkins = JSON.parse(xmlhttp.responseText);
var numeroCheckins = checkins.length;
var polylineCheckins = [];
var bounds = new google.maps.LatLngBounds();
for (counter = 0; counter< numeroCheckins; counter++)
{
var posizione = new google.maps.LatLng(checkins[counter].lat,
checkins[counter].long);
polylineCheckins[counter] = posizione;
bounds.extend(posizione);
}
var polyline = new google.maps.Polyline({
path: polylineCheckins,
strokeColor: "#FF0000",
strokeOpacity: 0.5,
strokeWeight: 5
});
polyline.setMap(map);
map.fitBounds(bounds);
}
一切正常,但如果多次調用此函數,則始終顯示上一行。我試圖使用方法setMap(null)但沒有成功,試圖重置折線。
我想在繪製一個新的之前實現刪除以前的折線的結果。
感謝您的支持
感謝您的支持! – maxdangelo