admin管理员组文章数量:1287517
I would like to remove a marker in Google Maps, but I don´t understand this. Please help me.
My 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);
How can I use setMap(Null);
? I don´t understand this.
I would like to remove a marker in Google Maps, but I don´t understand this. Please help me.
My 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);
How can I use setMap(Null);
? I don´t understand this.
1 Answer
Reset to default 7Try making a button and a listener to test your code.
To remove a marker from the map, call the setMap() method passing null as the argument.
marker.setMap(null);
Note that the above method does not delete the marker. It simply removes the marker from the map. If instead you wish to delete the marker, you should remove it from the map, and then set the marker itself to
null
.
Following the sample code in the 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 = [];
}
To remove a single marker, see the related SO question code snippet:
marker.addListener("dblclick", function() {
marker.setMap(null);
});
Hope this helps!
本文标签: javascriptRemove Marker in Google API V3Stack Overflow
版权声明:本文标题:javascript - Remove Marker in Google API V3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741312850a2371747.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论