简体   繁体   English

如何将HTML和KML与Google-Earth-Plugin结合?

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

First, I want to thank you for the efforts in answering. 首先,我要感谢您的回答。

Second, I created a site that contains a plug-in of Google Earth, and I want to use a local KML file to show two coordinates. 其次,我创建了一个包含Google Earth插件的网站,并且我想使用本地KML文件显示两个坐标。

HTML code: 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 code: 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>

I searched Google for some answers, but nothing helped me to understand how to combine between the HTML and KML (Google Earth Plug-in). 我在Google上搜索了一些答案,但没有任何帮助我了解如何在HTML和KML(Google Earth插件)之间结合。 please help me. 请帮我。 Thank you very much, Orian. 非常感谢您,奥利安。

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);
}

or 要么

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 https://developers.google.com/earth/articles/earthapikml

"use a local KML file" “使用本地 KML文件”

Using the file:// handler in the browser may satisfy your needs, using a web-browser to access local files has it's own gotchas though, from security restrictions onwards. 从安全性限制开始,在浏览器中使用file://处理程序可能会满足您的需要,但是使用Web浏览器访问本地文件是否有其自身的麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM