【问题标题】:Gmaps search and kmz load javascriptGmaps 搜索和 kmz 加载 javascript
【发布时间】:2015-04-08 09:43:41
【问题描述】:

我有一个网站,我可以在该网站上加载和使用 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

【问题讨论】:

    标签: javascript google-maps geolocation kmz


    【解决方案1】:

    来自GMaps documentation

    此外,loadFromKML 接受 google.maps.KmlLayerOptions 中定义的任何选项。

    使用{preserveViewport: true} 选项。

    preserveViewport boolean 默认情况下,输入地图居中并缩放到图层内容的边界框。如果此选项设置为 true,则视口保持不变,除非从未设置地图的中心和缩放。

    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);
          }
        }
    

    【讨论】:

    • 非常感谢先生 :D 你拯救了这一天 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    • 2014-10-18
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多