Gmaps 搜索和 kmz 加载 javascript

Gmaps search and kmz load javascript

我有一个加载和使用 kmz 文件的网站。我的问题是 GEO 位置不工作,我的意思是它工作但它没有显示街道因为 Javascript 加载 kmz 文件并将焦点设置在 KMZ 地图而不是你的 GEOlocation。

无论如何,这是代码,您可以看看哪里出了问题:

 <script type="text/javascript">
    var map, infoWindow;
    $(document).ready(function(){
      infoWindow = new google.maps.InfoWindow({});
      map = new GMaps({
        el: '#map',
        zoom: 20,
        lat: 46.044414,
        lng: 14.508105,
      });
      map.loadFromKML({
        url: 'http://blabla.com/blabla.kmz',
        url: 'http://blabla.com/blabla2.kmz',
        suppressInfoWindows: true,
        events: {
          click: function(point){
            infoWindow.setContent(point.featureData.infoWindowHtml);
            infoWindow.setPosition(point.latLng);
            infoWindow.open(map.map);
          }
        }
      });
    });
  </script>
<script type="text/javascript">
GMaps.geolocate({
  success: function(position) {
    map.setCenter(position.coords.latitude, position.coords.longitude);
  },
  error: function(error) {
    alert('Geolocation failed: '+error.message);
  },
  not_supported: function() {
    alert("Your browser does not support geolocation");
  },
  always: function() {
    alert("Success!");
  }
});
</script>

哦差点忘了,我用的是Gmaps.js

来自GMaps documentation

Also, loadFromKML accepts any option defined in google.maps.KmlLayerOptions.

使用 {preserveViewport: true} 选项。

preserveViewport boolean 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.

map.loadFromKML({
    url: 'http://blabla.com/blabla.kmz',
    url: 'http://blabla.com/blabla2.kmz',
    preserveViewport: true,
    suppressInfoWindows: true,
    events: {
      click: function(point){
        infoWindow.setContent(point.featureData.infoWindowHtml);
        infoWindow.setPosition(point.latLng);
        infoWindow.open(map.map);
      }
    }