Yet another {"error": "Please use POST request"}
from jsFiddle is thwarting my attempt to delete a google-maps-api-3 marker after getting confirmation from the user. My jsFiddle code is here. You can see the error by first creating one or more markers by clicking on the map, and then right-clicking on one of the markers. Finally, click on the "Delete" button.
The code borrows heavily from this code.
EDIT
3 corrections.
As pointed out in a comment, I had not updated the jsFiddle. A corrected version can be found at /5/. The main diff is that the line of code inside the Listener for 'rightclick' is commented out, as it should have been all along.
That same correction of commenting out a line of code is done below.
I am no longer getting the error "{"error": "Please use POST request"}" unless I make a manual change to the jsfiddle code (such as deleting the commented out line altogether), then Control-Return, and then try to add and delete markers. So that is no longer a problem, I believe. Instead the new problem is that if there are multiple markers and I click on just one of them and request its deletion, instead all markers are deleted. So I really need some help to accomplish my goal of deleting markers, one at a time.
The code below
EDIT
var map
var infowindow;
var markers = [];
function initialize() {
var NY = new google.maps.LatLng(40.739112, -73.785848);
map = new google.maps.Map(
document.getElementById('map-canvas'), {
center: NY,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
google.maps.event.addListener(map, 'click', function (event) {
addMarker(event.latLng);
});
}
function addMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
markers.push(marker);
var delform = marker.getPosition() + '<br />' + '<form onsubmit="processdel(this,marker); return false" action="#">' + ' <input type="submit" id="delid" value="Delete" />' + '</form>';
infowindow = new google.maps.InfoWindow({
content: delform,
size: new google.maps.Size(50, 50)
});
google.maps.event.addListener(marker, 'rightclick', function (event) {
infowindow.open(map, marker);
// marker.setMap(null); This is the line that was NOT supposed to be in the code.
});
}
function processdel(form, marker) {
infowindow.close();
marker.setMap(null);
marker = null;
}
initialize();
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…