Here's what my code looks like to get information from the server to
display on the map:
function update_locations () {
bounds = map.getBounds();
sw = bounds.getSouthWest();
ne = bounds.getNorthEast();
$.getJSON('/locations/locations/',
{'lat1':sw.lat(), 'long1':sw.lng(),
'lat2':sw.lat(), 'long2':ne.lng(),
'lat3':ne.lat(), 'long3':ne.lng(),
'lat4':ne.lat(), 'long4':sw.lng()},
function(data, textStatus){
$.each(data, function() {
//Check if currently in set, add if not
if (markerSet["key"+
this.id]) {}
else {
latlng = new GLatLng(this.latitude,
this.longitude);
marker = new GMarker(latlng,
{'title':
this.name});
marker.bindInfoWindowHtml("<iframe src=\"/
locations/info/"+
this.id+"/\"></iframe>");
markerSet["key"+
this.id] = marker;
markerManager.addMarker(marker, 10);
}
});
}
);
}
In my onload event handler for the page, I have this:
GEvent.addListener(map, 'moveend', update_locations);
I don't have access to the Django view that responds to the request
right now, but I could post it later if it would be helpful. It
basically just creates a polygon from the lat/long GET parameters and
then does a GeoDjango query for the points inside that polygon. It
then iterates over them and constructs a JSON-encoded list of
JavaScript objects, which it puts into the HTTPResponse.
The code uses JQuery, which I've found really helpful in reducing the
pain of Javascript. That's what all the funny $ variables are. Does
this make sense?