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

其次,我创建了一个包含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地球插件)之间结合。请帮我。
非常感谢你,
奥利安。

最佳答案

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浏览器访问本地文件是否有其自身的麻烦。

关于javascript - 如何将HTML和KML与Google-Earth-Plugin结合?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26243927/

10-12 15:16