Forum Moderators: open
I could use some advice here. I have a map with multiple markers. On each marker I am setting an event listener, which should pan the map to that point and zoom.
The problem I am having is that it will only zoom to the last "point" that was set during the for loop.
I've highlighted the problem areas below. What I need to do is pass the current point value to each listener. Really appreciate any advice givin.
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(39.021667, -105.505278), 7);
GDownloadUrl("data.php", function(data, responseCode) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
var mgr = new GMarkerManager(map);
var points = [];
for (var i = 0; i < markers.length; i++) {
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var title = markers[i].getAttribute("title");
var m = new GMarker(point, { title: title });
GEvent.addListener(m, "click", function() {
map.setCenter(point, 7);
});
points.push( m );
}
mgr.addMarkers(points, 0, 9);
mgr.refresh();
});
}
}