当我根据此stackoverflow question将preserveViewport:true
添加到kmlLayer选项时,Google地图开始抛出'未捕获的TypeError:无法读取属性'lat'为'错误'。
这是小提琴: 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);
答案 0 :(得分:0)
没关系,地图停止使用KML的中心并转到mapOptions,它是
center: google.maps.LatLng(41.875696,-87.624207),
必须将其更改为
center: new google.maps.LatLng(41.875696,-87.624207),