I can't achieve zoom on kml map, I am using same solution that is given here:
google-maps-zoom-gets-over-riden-when-using-a-kml-file . You can see my jsfiddle here:
jsfiddle for kml map zoom.
If I remove preserveViewport: true
from that example it will load the map with it I am not getting map.
Asked
Active
Viewed 164 times
0
2 Answers
2
The map needs to be initialized with a center. You are currently not doing that if you set preserveViewport to false; where do you expect the map to be centered?
Your (problematic) code:
var myOptions = {
zoom: 20,
center: null,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("kmlMapCanvas"), myOptions);
Either set the center explicitly or let the KmlLayer do it for you.
From the documentation:
- center LatLng The initial Map center. Required.

geocodezip
- 158,664
- 13
- 220
- 245
-
I thought that we can zoom further when google center the map, so it was mine misconception. – jasin_89 Nov 14 '12 at 20:56
-
What does that mean? "zoom further when google center the map"? You can zoom in more, or zoom out further, once the KML is loaded and the KmlLayer has set the zoom to show its contents. You just have to wait for the event that says that has happened. – geocodezip Nov 14 '12 at 21:02