The KML file included in google drive that does not recognize

久未见 提交于 2021-01-28 18:22:14

问题


I have tried Displaying KML files in my google Maps application. I used google map api documentation for that.

when I load my HTML file, it show only google map. I think this problem about KML file. How do i fix it ..? I have upload KML file into my google drive and I share it as "anyone with the link can edit". However Google Maps API's example is working...!!

this is the code :-

<script>
var map;
var src = 'https://drive.google.com/open?id=0B5oAxCVEQK5uZ0tJcFBDaGRfajg';

 function initialize() {
 map = new google.maps.Map(document.getElementById('map'), {
     center: new google.maps.LatLng(7.742291, 80.529785),
     zoom: 7,
     mapTypeId: google.maps.MapTypeId.TERRAIN
 });
 loadKmlLayer(src, map);
 }

  var kmlUrl = 'https://drive.google.com/open?id=0B5oAxCVEQK5uZ0tJcFBDaGRfajg';
 var kmlOptions = {
 suppressInfoWindows: true,
 preserveViewport: false,
 map: map
  };
 var kmlLayer = new google.maps.KmlLayer(kmlUrl, kmlOptions);

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;
    });}
     google.maps.event.addDomListener(window, 'load', initialize);
 </script>

回答1:


This is the solution for the question. This whole code is correct, and also kml file is correct. The point is, we are unable to put kml file in google Drive or Dropbox. you must host the KML file on a server. for that you can use Google Sites to host Your KML.

May be useful :- Display KML in a Google Map and below google api

https://developers.google.com/maps/documentation/javascript/tutorials/kml#overview



来源:https://stackoverflow.com/questions/37492260/the-kml-file-included-in-google-drive-that-does-not-recognize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!