как удалить гугл геокод по клику - PullRequest
1 голос
/ 21 января 2011

Я использую 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);
  }
});

1 Ответ

1 голос
/ 21 января 2011

Если вы используете API v3, попробуйте:

marker.setMap(null);

Это удалит его с карты.

http://code.google.com/apis/maps/documentation/javascript/reference.html#Marker

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...