我使用Google Maps Api3来显示我的KML标记。我已将LatLng设置为居中并放大某个位置,但地图似乎会自动缩小以显示所有标记(我不想要)
这是我的javascript:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/jskey=XXX&sensor=false"></script>
<script type=text/javascript>
function initialize() {
var foo = new google.maps.LatLng(58.404590,-15.743408);
var mapOptions = {
zoom: 11,
center: foo,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var ctaLayer = new google.maps.KmlLayer({
url: 'mykml.kml'
});
ctaLayer.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);</script>
有什么想法吗?
答案 0 :(得分:1)
将preserveViewport: true
添加到您的KMLLayerOptions:
默认情况下,输入地图居中并缩放到图层内容的边界框。如果此选项设置为true,则视口保持不变,除非从未设置地图的中心和缩放。
https://developers.google.com/maps/documentation/javascript/reference#KmlLayerOptions
var ctaLayer = new google.maps.KmlLayer({
url: 'mykml.kml',
preserveViewport: true
});