【问题标题】:How to combine HTML and KML with Google-Earth-Plugin?如何将 HTML 和 KML 与 Google-Earth-Plugin 结合起来?
【发布时间】:2014-10-07 19:42:29
【问题描述】:

首先,我要感谢您为回答所做的努力。

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

【问题讨论】:

标签: javascript html kml google-earth-plugin


【解决方案1】:
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:// 处理程序可能会满足您的需求,但是从安全限制开始,使用网络浏览器访问本地文件有它自己的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多