2014-10-27 55 views
1

基本上,我试图在我的网站上添加/显示我的Google地球div上的KML文件。我打电话给我的文件“satellites.kml”。如何将Google地球KML文件添加到html iframe?

<!-- html code starts...--> 

<p><iframe 
     name="myKMLEarth" 
     src="/getrack/satellites.kml" 
     height="440" 
     width="100%" 
     frameborder="0" 
     scrolling="no"> 
</iframe></p> 

<!-- html code continues ...--> 

当页面加载时,它下载我的KML而不是在iframe中打开它。我不应该使用src链接到KML文件吗?任何意见,将不胜感激!先谢谢你!

+0

你想做什么?以明文形式显示.kml文件的联系人? – Bijan 2014-10-27 23:38:01

+0

我正在尝试将我的KML图层添加到网站上显示的Google地球上。 – MadsterMaddness 2014-10-27 23:39:28

+1

你为什么使用iframe?你可以添加'satellites.kml'作为一个新层。看到[这里](http://stackoverflow.com/questions/17409598/toggle-multiple-kml-kml-layers-in-google-maps-api-v3)如何做别人 – Bijan 2014-10-27 23:42:47

回答

3

你必须使用谷歌地图JavaScript API https://developers.google.com/maps/documentation/javascript/reference?hl=es

您必须将google.maps.KmlLayer附加到地图上。

把API脚本在<head>

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"></script> 

创建这样一个div:

<div id="google-map" class="google-map"></div> 

然后,使用这个JS代码</body>之前。设置您的纬度,经度和KML文件的路径。

<script> 
    function initialize() { 
     var mapOptions = { 
      center: new google.maps.LatLng(YOUR_LAT,YOUR_LNG), //Set your latitude, longitude 
      zoom: 19, 
      mapTypeId: google.maps.MapTypeId.SATELLITE, 
      scrollwheel: false 
     } 

     var map = new google.maps.Map(document.getElementById('google-map'), mapOptions); // get the div by id 

     var ctaLayer = new google.maps.KmlLayer({ 
      url: 'PATH/TO/FILE.kml' // Set the KML file 
     }); 

     // attach the layer to the map 
     ctaLayer.setMap(map); 
    } 

    // load the map 
    google.maps.event.addDomListener(window, 'load', initialize); 
</script> 
1

您似乎需要在另一个应用程序或使用插件打开KML。浏览器不知道如何在iframe中显示文件,因此只需下载它。 “许多应用程序都显示KML,包括Google地球,Google地图,Google地图移动版,NASA WorldWind,ESRI ArcGIS Explorer,Adobe PhotoShop,AutoCAD和Yahoo! Pipes。”

我不100%明白你正在尝试做的,所以我不能肯定,如果这是你在找什么,但这个问题可能指向您在正确的方向:How to Embed KML files (Google Earth) into a website without the google gadget?

相关问题