1
我正在使用谷歌地圖 - 方向和地理編碼。加載頁面時,地理編碼會放置一個標記。當用戶點擊提交按鈕時是否可以刪除該標記?如何刪除谷歌地理編碼點擊
下面是代碼:
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);
}
});
我會在哪放置該代碼?我嘗試過: var marker = new google.maps.Marker(null); – 2011-01-21 06:41:33