Search code examples
javascriptgoogle-mapsgoogle-maps-api-3zooming

map.setZoom() is not working but map.setCenter() is working


Part of my code looks like this, I am able to center the map using

map.setCenter(myLatlng);

but after that I am trying to zoom the map

marker_id = id;
marker_id = new google.maps.Marker();

marker_id.setIcon(image);
myLatlng = new google.maps.LatLng(loctionupdateobj[id].lat, loctionupdateobj[id].lang);
marker_id.setPosition(myLatlng);        
marker_id.setMap(map);      

map.setCenter(myLatlng);

alert(map.getZoom());
map.setZoom(10);
alert("game again " + map.getZoom())

You can see the

alert("game again " + map.getZoom())

in the code it is giving me an alert like game again 10 but the zoom level is never going to 10.

But the first alert is 4 (which I set during initialsation).

As I am not able to setZoom, I am creating a new map instance each time when I am adding new markers.


Solution

  • Finally found !!! The previous programmer who coded my project wrote a line

    google.maps.event.clearListeners(map);