Google Maps zoom gets overriden, when using a kml file 2

痞子三分冷 提交于 2020-01-07 08:25:16

问题


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.


回答1:


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.



回答2:


It seems like it is working fine. :) Are you sure?



来源:https://stackoverflow.com/questions/13386762/google-maps-zoom-gets-overriden-when-using-a-kml-file-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!