簡體   English   中英

如何將HTML和KML與Google-Earth-Plugin結合?

[英]How to combine HTML and KML with Google-Earth-Plugin?

首先,我要感謝您的回答。

其次,我創建了一個包含Google Earth插件的網站,並且我想使用本地KML文件顯示兩個坐標。

HTML代碼:

<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"> </script>
<script type="text/javascript">
var ge;
google.load("earth", "1", {"other_params":"sensor=false"});

var fso, kmlString, fh;

function init() {
  google.earth.createInstance('map3d', initCB, failureCB);
}

function initCB(instance) {
  ge = instance;
  ge.getWindow().setVisibility(true);
}

function failureCB(errorCode) {
}

google.setOnLoadCallback(init);

</script>
</head>
<body>
    <div id="map3d" style="height: 300px; width: 400px;"></div>
</body>
</html>

KML代碼:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Simple placemark</name>
<description>Attached to the ground. Intelligently places itself 
   at the height of the underlying terrain.</description>
<Point>
  <coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
</Point>
</Placemark>
</kml>

我在Google上搜索了一些答案,但沒有任何幫助我了解如何在HTML和KML(Google Earth插件)之間結合。 請幫我。 非常感謝您,奧利安。

function initCallback(pluginInstance) {
  ge = pluginInstance;
  ge.getWindow().setVisibility(true);

  // Earth is ready, we can add features to it
  addKmlFromUrl('http://path/to/your.kml');
}

function addKmlFromUrl(kmlUrl) {
  var link = ge.createLink('');
  link.setHref(kmlUrl);

  var networkLink = ge.createNetworkLink('');
  networkLink.setLink(link);
  networkLink.setFlyToView(true);

  ge.getFeatures().appendChild(networkLink);
}

要么

function addKmlFromUrl(kmlUrl) {
  google.earth.fetchKml(ge, kmlUrl, kmlFinishedLoading);
}

function kmlFinishedLoading(kmlObject) {
  if (kmlObject) {
    ge.getFeatures().appendChild(kmlObject);
  }
}

https://developers.google.com/earth/articles/earthapikml

“使用本地 KML文件”

從安全性限制開始,在瀏覽器中使用file://處理程序可能會滿足您的需要,但是使用Web瀏覽器訪問本地文件是否有其自身的麻煩。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM