【问题标题】:Google map throws error when adding 'preserveViewport:true' to kmlLayer options将“preserveViewport:true”添加到 kmlLayer 选项时,Google 地图会引发错误
【发布时间】:2014-10-05 06:40:39
【问题描述】:

当我基于此stackoverflow questionpreserveViewport:true 添加到 kmlLayer 选项时,Google 地图开始抛出“Uncaught TypeError: Cannot read property 'lat' of null ”错误。

这是小提琴: http://jsfiddle.net/svp70tjx/1/

html:

<div id="map"></div>

javascript:

function initialize() {
            var mapOptions = {
                scrollwheel: false,
                zoom: 11,
                center: google.maps.LatLng(41.875696,-87.624207),
                styles: [{"featureType":"administrative","elementType":"all","stylers":[{"visibility":"on"},{"saturation":-100},{"lightness":20}]},{"featureType":"road","elementType":"all","stylers":[{"visibility":"on"},{"saturation":-100},{"lightness":40}]},{"featureType":"water","elementType":"all","stylers":[{"visibility":"on"},{"saturation":-10},{"lightness":30}]},{"featureType":"landscape.man_made","elementType":"all","stylers":[{"visibility":"simplified"},{"saturation":-60},{"lightness":10}]},{"featureType":"landscape.natural","elementType":"all","stylers":[{"visibility":"simplified"},{"saturation":-60},{"lightness":60}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"off"},{"saturation":-100},{"lightness":60}]},{"featureType":"transit","elementType":"all","stylers":[{"visibility":"off"},{"saturation":-100},{"lightness":60}]}],
                zoomControlOptions: {
                    style: google.maps.ZoomControlStyle.SMALL
                }
            }

            var map = new google.maps.Map(document.getElementById('map'), mapOptions);

            var ctaLayer = new google.maps.KmlLayer(
                'https://maps.google.com/maps/ms?msa=0&msid=209537462410499505635.0004d278fb32588bd6da3&ie=UTF8&t=h&ll=48.985492,18.191269&spn=0.27644,0.427604&output=kml',
                {
                    suppressInfoWindows: true,
                    map: map,
                    preserveViewport: true
                }
            );
            ctaLayer.setMap(map);
        }

        google.maps.event.addDomListener(window, 'load', initialize);

【问题讨论】:

    标签: javascript google-maps


    【解决方案1】:

    没关系,地图停止使用 KML 的中心并转到它所在的 mapOptions

    center: google.maps.LatLng(41.875696,-87.624207),
    

    不得不改成

    center: new google.maps.LatLng(41.875696,-87.624207),
    

    【讨论】:

      猜你喜欢
      • 2012-10-31
      • 1970-01-01
      • 2016-08-14
      • 2016-08-28
      • 2016-05-30
      • 1970-01-01
      • 2019-02-10
      • 1970-01-01
      • 2020-04-06
      相关资源
      最近更新 更多