Hi,
I am new to Google maps and javascript, and am hitting a wall while
following the documentation on events and listeners for V3.
I followed the instructions for adding a listener to recenter the map
on the city of Darwin when zoom_changed is fired by the API, as
indicated here:
http://code.google.com/apis/maps/documentation/javascript/events.html#EventListeners
My code seems fine:
var centerLatitude = 37.818361
var centerLongitude = -122.198032
var startZoom = 3
function initialize() {
var latlng = new google.maps.LatLng(centerLatitude,
centerLongitude);
var myOptions = {
zoom: startZoom,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new
google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map, 'zoom_changed', function() {
setTimeout(moveToDarwin, 3000);
});
var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"Hello World!"
});
google.maps.event.addListener(marker, 'click', function() {
map.setZoom(12);
});
}
function moveToDarwin() {
var darwin = new google.maps.LatLng(-12.461334, 130.841904);
map.setCenter(darwin);
}
The map loads fine, the marker created in the code is present and
responds to the 'click' event by zooming, as expected.
But when I zoom (either manually or via clicking the marker), I don't
get the expected behavior of the map automatically recentering to the
specified coordinates. Is it possible that 'zoom_changed' isn't being
fired? How can I debug this? Is it possible to check this with
Firebug?
Any help is appreciated. Like I said, I'm very new to this and I
realize this might seem like a dumb question, but I have been trying
to figure this out for the last day and I am at a dead end.
Thanks in advance.