Google Map with KML will not perform zoom adjustments; Instead, scales to fit all markers

Using the Javascript API of Google Maps V3, I configured the map to extract data from a dynamically generated KML file. Here is the result: http://theevolvement.org/MapRetailers.php

In my code (copied below) I defined a scale of up to 12 in my map settings. When a page loads, it starts with the designated zoom, but within about one second, the map zooms in (and shifts the designated center) to fit all the plotted points.

We want to load the map with the specified increase, and not include all the data built. Therefore, any advice that may give what I am doing wrong would be greatly appreciated. Thanks everyone!

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> function initialize() { var vegas = new google.maps.LatLng(36.1589862,-115.1723833); var myOptions = { zoom: 12, center: vegas, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var ctaLayer = new google.maps.KmlLayer('http://theevolvement.org/MapRetailers.php?getKML=1&t=<?=mktime()?>'); ctaLayer.setMap(map); } </script> </head><body onload="initialize()"> <div id="map_canvas"></div> </body> 
+4
source share
1 answer

WOO! I finally figured out the solution!

The KmlLayer function requires one more parameter: {preserveViewport: true}

  var ctaLayer = new google.maps.KmlLayer('<?=$kmlURL?>', {preserveViewport: true}); 
+9
source

Source: https://habr.com/ru/post/1379237/


All Articles