Here's the problem:
I want to remove all map markers from the map when they go out of the viewport. I have the code that checks for their position, then runs setMap(null) on the marker. The marker disappears. I then set the marker itself to null to destroy it, per the Google Maps documentation.
The problem is that jquery-maps-ui's function for retrieving the map markers still includes the deleted markers!
function cleanUpMarkers(map) {
console.log("$('#map_canvas').gmap('get', 'markers').length = " + $('#map_canvas').gmap('get', 'markers').length);
$.each($('#map_canvas').gmap('get', 'markers'), function (i, marker) {
if (!map.getBounds().contains(marker.getPosition())) {
console.log(marker.internalId);
marker.setMap(null);
marker = null;
delete marker;
//console.log(marker.internalId);
}
});
console.log("$('#map_canvas').gmap('get', 'markers').length = " + $('#map_canvas').gmap('get', 'markers').length);
}
How can I truly delete the marker so that $('#map_canvas').gmap('get', 'markers') doesn't return the deleted markers?