Я использую Google Maps - маршруты и геокодирование. Геокод размещает маркер при загрузке страницы. Можно ли удалить этот маркер, когда пользователь нажимает кнопку отправки?
Вот код:
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);
}
});