【问题标题】:Importing and Parsing KML files in GoogleMap在 GoogleMap 中导入和解析 KML 文件
【发布时间】:2017-03-22 15:36:49
【问题描述】:

我正在尝试将 Google Maps API 与直接在 Google Maps 平台中创建并导出到 .kml 文件的新图层一起使用。使用的指南是 Google Developer 门户网站上的主要指南。

但是,KML 文件似乎无法正确加载。 http://1c.1contact.ch/mandats/map1.html

连接和加载地图的代码如下(改编自https://developers.google.com/maps/documentation/javascript/kmllayer):

<script>
  var map;
  var src = 'http://1c.1contact.ch/file/2573/GE.kml';

  /**
  * Initializes the map and calls the function that loads the KML layer.
  */
  function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
  center: new google.maps.LatLng(-19.257753, 146.823688),
  zoom: 2,
  mapTypeId: 'terrain'
  });
  loadKmlLayer(src, map);
  }

  /**
  * Adds a KMLLayer based on the URL passed. Clicking on a marker
  * results in the balloon content being loaded into the right-hand div.
  * @param {string} src A URL for a KML file.
  */
  function loadKmlLayer(src, map) {
  var kmlLayer = new google.maps.KmlLayer(src, {
  suppressInfoWindows: true,
  preserveViewport: false,
  map: map
  });
  google.maps.event.addListener(kmlLayer, 'click', function(event) {
  var content = event.featureData.infoWindowHtml;
  var testimonial = document.getElementById('capture');
  testimonial.innerHTML = content;
  });
  }
</script>

完成此 .KML 使用的正确方法是什么?

祝你好运,

【问题讨论】:

    标签: parsing import maps kml layer


    【解决方案1】:

    您指定的 KML 文件 (http://1c.1contact.ch/file/2573/GE.kml) 不会加载,因为它不能在网络上公开访问。它似乎位于该服务器上的登录页面后面。即使您使用浏览器登录,Google 地图代码和渲染系统也无法访问该文件,因此您需要将其放在可公开访问的位置。

    【讨论】:

      猜你喜欢
      • 2013-08-30
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      • 2012-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-02
      相关资源
      最近更新 更多