Reputation: 1515
I'm using Google Maps Api3 to show my KML markers. I've set the LatLng to center and zoom on a location, but the map seems to automatic zoom out to show all the markers (I don't want that)
Here's my 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>
Any ideas?
Upvotes: 0
Views: 167
Reputation: 31912
Add preserveViewport: true
to your KMLLayerOptions:
By default, the input map is centered and zoomed to the bounding box of the contents of the layer. If this option is set to true, the viewport is left unchanged, unless the map's center and zoom were never set.
https://developers.google.com/maps/documentation/javascript/reference#KmlLayerOptions
var ctaLayer = new google.maps.KmlLayer({
url: 'mykml.kml',
preserveViewport: true
});
Upvotes: 1