1
我正在使用谷歌地圖 - 方向和地理編碼。加載頁面時,地理編碼會放置一個標記。當用戶點擊提交按鈕時是否可以刪除該標記?我早前問過,有人建議使用:在onclick後刪除地理編碼標記
marker.setMap(null);
,但我不太清楚在什麼地方的代碼
這裏說一位爲代碼:
var address = document.getElementById("address").textContent.replace(/\n/g, " ");
geocoder.geocode({ 'address': address},
function(results, status)
{
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
var from = document.getElementById("from").value;
var to = document.getElementById("to").value;
var request = {
origin: from,
destination: to,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
document.getElementById("map").style.width = "70%";
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
在此先感謝
你介意解釋我輸入的一些代碼嗎? 1. var markersArray = []; 2. markersArray.push(marker); (標記陣列){ markersArray [i] .setMap(null); } markersArray.length = 0; } – 2011-01-21 17:55:54
[如何刪除谷歌地理編碼點擊](http://stackoverflow.com/questions/4754407/how-to-remove-google-geocode-on-click)可能重複 – L84 2015-10-22 01:22:04