0

我正在使用 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>

有任何想法吗?

4

1 回答 1

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
});
于 2013-05-24T10:22:35.903 回答