问题
When I add multiple kmllayers to a map it ignores the zoom level and center that I've set for the map and instead centers on the last added layer.
Can someone tell me how I'm suppose to set the zoom level and center of the map?
<script>
function initialize()
{
var location = new google.maps.LatLng(52.0,5.1);
var mapOptions = {
zoom: 15,
center: location,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
//Add MapLayers
var mapLayer1 = new google.maps.KmlLayer({
url: 'http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml'
});
mapLayer1.setMap(map);
var mapLayer2 = new google.maps.KmlLayer({
url: 'http://kml-samples.googlecode.com/svn/trunk/kml/kmz/balloon/balloon-image-rel.kml'
});
mapLayer2.setMap(map);
var mapLayer3 = new google.maps.KmlLayer({
url: 'http://kml-samples.googlecode.com/svn/trunk/kml/time/time-stamp-point.kml'
});
mapLayer3.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
回答1:
Set preserveViewport: true for all your KmlLayers
来源:https://stackoverflow.com/questions/16818638/zoom-and-center-not-working-when-using-multiple-kmllayers-google-maps