如果我双击我的KML文件,它会做它应该做的事情,并启动GE,并按预期执行。当我把它放到我的HTML文件中时,它将无法工作。然后我把它放到http://earth-api-samples.googlecode.com/svn/trunk/examples/kml-fetch-interactive.html中,它在那里也不起作用。这是到荷兰皇家航空公司https://dl.dropbox.com/u/61240296/myPoints.Kml的链接。它基本上是Google示例的直接副本。KML文件是否依赖于其他KML文件?我注意到的一件事是没有道路,所以看起来似乎没有任何KML文件是打开或激活的。
<?xml version="1.0" encoding="UTF-8"?>xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:kml="http://www.opengis.net/kml/2.2"
xmlns:atom="http://www.w3.org/2005/Atom">
<Camera>
<longitude>-93.2539393007755</longitude>
<latitude>45.5456585437059</latitude>
<altitude>139.629438</altitude>
<heading>-70.0</heading>
<tilt>75</tilt>
</Camera>
<Placemark>
<name>Placemark from KML file</name>
<Point>
<coordinates>-93.2539393007755, 45.5456585437059</coordinates>
</Point>
</Placemark>
</Document>
</kml>发布于 2012-10-23 02:55:04
您的KML文件没有问题。它在您链接到的示例页面中也可以完美地工作。问题是加载kml文件后,示例页面不会更改视图。它甚至都不会尝试。
编辑此函数
function finishFetchKml(kmlObject) {
// check if the KML was fetched properly
if (kmlObject) {
// add the fetched KML to Earth
currentKmlObject = kmlObject;
ge.getFeatures().appendChild(currentKmlObject);
} else {
// wrap alerts in API callbacks and event handlers
// in a setTimeout to prevent deadlock in some browsers
setTimeout(function() {
alert('Bad or null KML.');
}, 0);
}
}看起来像这样
function finishFetchKml(kmlObject) {
// check if the KML was fetched properly
if (kmlObject) {
// add the fetched KML to Earth
currentKmlObject = kmlObject;
ge.getFeatures().appendChild(currentKmlObject);
///////////////////////////////////////////////
// this is what you need to add
var myView = currentKmlObject.getAbstractView();
ge.getView().setAbstractView(myView);
//////////////////////////////////////////////
} else {
// wrap alerts in API callbacks and event handlers
// in a setTimeout to prevent deadlock in some browsers
setTimeout(function() {
alert('Bad or null KML.');
}, 0);
}
}然后,您需要决定是将该<Camera>视图分配给<Placemark>还是<Document>,如果您没有意识到,您的<Camera>视图并不查看<Placemark>,而是从<Placemark>正上方的某个点查看地平线
发布于 2012-10-25 19:07:46
如果你试图加载一个格式良好的KML文件,但该文件没有正确加载,你应该会看到使用chrome,firebug或类似的开发工具的web服务器的头文件。如果你使用apache作为你的you服务器,你应该在你的httpd.conf中添加:
AddType应用程序/vnd.google-地球.kml +xml.kml AddType应用程序/vnd.google-地球.kmz .kmz
https://stackoverflow.com/questions/13014963
复制相似问题