2016-09-04 3 views
0

Google지도에서 마커를 제거하고 싶지만 이해가 안됩니다. 도와주세요.Google API V3에서 마커 제거

내 Validation.js :

function initialize() { 
//geocodierungs Funktion damit Geocoding funktioniert 
geocoder = new google.maps.Geocoder(); 
var mapOptions = { 
    zoom:5, 
    center: new google.maps.LatLng(48.136607,11.577085), 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
}; 
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); 

var pos=new google.maps.LatLng(48.2,11); 
var marker = new google.maps.Marker({ 
    position:pos, 
    map:map, 
    title: 'test' 
});} setInterval(function(){   
     //$.post('nav_schnittstelle.php',{}).done(aktualisiereKartendaten); 
     alert('test'); 
     pos.setMap(null); },10000); 

어떻게 setMap(Null);를 사용할 수 있습니까? 나는 이것을 이해하지 못한다.

답변

0

단추 및 수신기를 만들어 코드를 테스트 해보십시오.

지도에서 마커를 제거하려면 setMap() 메소드를 호출하여 null을 인수로 전달하십시오.

marker.setMap (null);

위의 방법은 마커를 삭제하지 않습니다. 단순히지도에서 마커를 제거합니다. 대신 마커를 삭제하려면지도에서 제거한 다음 마커 자체를 null으로 설정해야합니다. document에서 샘플 코드에 따라

:

// Adds a marker to the map and push to the array. 
function addMarker(location) { 
var marker = new google.maps.Marker({ 
position: location, 
map: map 
}); 
markers.push(marker); 
} 

// Sets the map on all markers in the array. 
function setMapOnAll(map) { 
for (var i = 0; i < markers.length; i++) { 
markers[i].setMap(map); 
} 
} 

// Removes the markers from the map, but keeps them in the array. 
function clearMarkers() { 
setMapOnAll(null); 
} 

// Shows any markers currently in the array. 
function showMarkers() { 
setMapOnAll(map); 
} 

// Deletes all markers in the array by removing references to them. 
function deleteMarkers() { 
clearMarkers(); 
markers = []; 
} 

단일 마커를 제거하려면 관련 SO question 코드 참조 :이 도움이

marker.addListener("dblclick", function() { 
marker.setMap(null); 
}); 

희망을!

관련 문제