我目前使用下面的代码向地图添加标记。我希望能够通过推送 javascript 命令随时删除任何一个。这可能吗?
前任。放置 5 个标记.. 删除第 3 个,同时保留其他 4 个。
$('#map').show();
var geocoder = new google.maps.Geocoder();
var address = document.getElementById("address").value +", " + document.getElementById("city").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
locationsall[counter] = new Array();
locationsall[counter][0] = address;
locationsall[counter][1] = lat;
locationsall[counter][2] = lng;
var mapOptions = {
zoom: 13,
center: new google.maps.LatLng(lat, lng),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker, i;
for (i = 0; i < locationsall.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locationsall[i][1], locationsall[i][2]),
map: map,
title: 'You are here!'
});
}
counter++;
} else {
alert("Geocode was not successful for the following reason: " + status);
}
}); }
编辑1:
}).text("Remove").click(function() {
var index2 = $tr2.index();
$("#locationDeals input[type='hidden']").each(function() {
this.name = this.name.replace(/\[(\d+)\]/, function(str2, number2) {
return "[" + (+number2 > index2 - 1 ? number2 - 1 : number2) + "]";
});
});
//locationsall[locations.indexOf(location)].setMap(null);
$tr2.remove();
locations.splice(locations.indexOf(location), 1);
return false;
}).appendTo($tdRemoveRow2);