Hi,
I'm drawing markers after a map has been panned or zoomed.
If the viewport has not totally changed than the markers that appeared
before the move and should still appear after it are being painted on
top of themselves again and again.
I know I have to delete all the markers from the map before the new
markers are painted and I know I should probably be using
marker.setMap(null);.
I just don't know how and where to fit it in my code:
google.maps.event.addListener(map, 'idle', showMarkers);
function showMarkers(){
// get viewport bounds
var southWestLat = map.getBounds().getSouthWest().lat();
var southWestLng = map.getBounds().getSouthWest().lng();
var northEastLat = map.getBounds().getNorthEast().lat();
var northEastLng =
map.getBounds().getNorthEast().lng();
var marker;
$.ajax({
type: "POST",
url: "markers.php",
dataType: "json",
data: ({'southWestLat' : southWestLat , 'southWestLng' :
southWestLng , 'northEastLat' : northEastLat , 'northEastLng' :
northEastLng}),
success: function(coordinatesMap){
for (var id in coordinatesMap){
if (coordinatesMap.hasOwnProperty(id))
{
marker = new google.maps.Marker({
position: new
google.maps.LatLng(coordinatesMap[id].lat,coordinatesMap[id].lng),
map: map
});
}
}
}
});
}
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.