私はgoogle maps-directionsとgeocodingを使用しています。ジオコードは、ページが読み込まれるときにマーカーを配置します。ユーザーが送信ボタンをクリックしたときにこのマーカーを削除することは可能ですか?私は先に尋ね、誰かが使用を提案した: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); 3. if(markersArray){ for(i in markersArray){ markersArray [i] .setMap(null); } markersArray.length = 0; } –
[Googleのジオコードをクリックして削除する方法]の複製が可能です(http://stackoverflow.com/questions/4754407/how-to-remove-google-geocode-on-click) – L84