【问题标题】:google earth load the KML file failed谷歌地球加载 KML 文件失败
【发布时间】:2012-08-14 06:30:18
【问题描述】:

我已经从谷歌地球导出了3D模型的KML文件(ICBC.kml),我想将3D模型加载到谷歌地球插件,但我无法得到结果,非常感谢您的建议.

用于加载 kml 的 JavaScript 代码

// Create the placemark.
var placemark = ge.createPlacemark('');
// Get the current view`enter code here`
var myCamera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);

// Set new latitude and longitude values
myCamera.setLatitude(30.55552076525944);
myCamera.setLongitude(114.3344795151639);
myCamera.setAltitude(500);

// Placemark/Model/Location
var loc = ge.createLocation('');
loc.setLatitude(myCamera.getLatitude());
loc.setLongitude(myCamera.getLongitude());


// Update the view in Google Earth
ge.getView().setAbstractView(myCamera);

var fso = new ActiveXObject("Scripting.FileSystemObject");

var f = fso.OpenTextFile("http://localhost/ICBC.kml",1,true);

var kmlobject = ge.parseKml(f.ReadAll());
ge.getFeatures().appendChild(kmlobject);
var la = ge.createLookAt('');
la.set(30.55552076525944, 114.3344795151639, 500, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 45, 900);
ge.getView().setAbstractView(la);

【问题讨论】:

    标签: kml google-earth


    【解决方案1】:

    如果你有KML file,你不应该使用parseKml,最好使用fetchKml,不需要传递Kml的字符串,只需传递URL KML。

    在你的情况下,你应该使用这一行:

    var href = UrlOfKML;
    
    google.earth.fetchKml(googleEarthInstance, href, function(kmlObject) {
          if (kmlObject)
             ge.getFeatures().appendChild(kmlObject);
    });
    

    如果您对fetchKmlparseKml 的区别有更多疑问,请查看此链接:Importing KML - GE docs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      • 1970-01-01
      • 2011-03-31
      • 1970-01-01
      相关资源
      最近更新 更多