Javascript 如何将HTML和KML与Google Earth插件相结合?

Javascript 如何将HTML和KML与Google Earth插件相结合?,javascript,html,kml,google-earth-plugin,Javascript,Html,Kml,Google Earth Plugin,首先,我要感谢你为回答这个问题所做的努力 其次,我创建了一个包含GoogleEarth插件的站点,我想使用一个本地KML文件来显示两个坐标 HTML代码: <html> <head> <script type="text/javascript" src="https://www.google.com/jsapi"> </script> <script type="text/javascript"> var ge; google.load

首先,我要感谢你为回答这个问题所做的努力

其次,我创建了一个包含GoogleEarth插件的站点,我想使用一个本地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>

var-ge;
load(“earth”、“1”、“其他参数”:“sensor=false”});
var fso,kmlString,fh;
函数init(){
createInstance('map3d',initCB,failureCB);
}
函数initCB(实例){
ge=实例;
ge.getWindow().setVisibility(true);
}
功能故障CB(错误代码){
}
setOnLoadCallback(init);
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>

简单地标
贴在地上。聪明地定位自己
在下面地形的高度。
-122.0822035425683,37.42228990140251,0
我在谷歌上搜索了一些答案,但没有任何东西帮助我理解如何将HTML和KML(谷歌地球插件)结合起来。请帮帮我。 非常感谢你, 奥利安

“使用本地KML文件”


在浏览器中使用
文件://
处理程序可以满足您的需要,但从安全限制开始,使用web浏览器访问本地文件有其自身的局限性。

var fso,kmlString,fh这些似乎与处理文件时丢失的某些代码有关。错过一些您正在使用的示例代码?也许这会有帮助
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);
  }
}