在无法解析我的GE的kml,我的代码有什么问题?我的代码将kml解析为Google Earth时出了什么问题?
我被困在这2周,并试图自己做许多其他的方式,
任何帮助将受到欢迎,
拉斐尔耶稣
google_earth.jsp
var ge;
google.load("earth", "1");
function init() {
google.earth.createInstance('map3d', initCB, failureCB);
window.scroll(0, 10000);
}
function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
// add a navigation control
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
// add some layers
ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
// directs the exact location of the placemark
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
lookAt.setLatitude(-15.26108113514467);
lookAt.setLongitude(-57.77290131815782);
lookAt.setRange(8007066.726300671);
ge.getView().setAbstractView(lookAt);
ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, false);
var kmlString = showPics();
// I put a alert in here and show in a window the value "undefined"
var kmlObject = ge.parseKml(kmlString);
ge.getFeatures().appendChild(kmlObject);
}
// dwr function that brings the kml with his values
// for now it is in hard coded, just for tests!!
function showPics() {
PainelEarthAjax.geraFotosObra({
callback : function(kmlString) {
// I put a alert function in here, and it has openned a window
// with the entire kmlString brought from the java method geraFotosObra().
return kmlString;
}
});
}
function failureCB(errorCode) {
}
google.setOnLoadCallback(init);
个
geraFotosObra.java
public String geraFotosObra() throws Exception {
try {
return new KMLGenerator().getKMLFromObra();
} catch (Exception e) {
log.error(e.getLocalizedMessage(), e);
return null;
}
}
KMLGenerator.java
public static String getKMLFromObra() {
StringBuffer sb = new StringBuffer();
sb.append("<?xml version='1.0' encoding='UTF-8'?>");
sb.append("<kml xmlns='http://www.opengis.net/kml/2.2' ");
sb.append("<Document>");
sb.append("<name>ConstruMobil</name>");
sb.append("<Style id='defaultStyles'>");
sb.append("<IconStyle>");
sb.append("<Icon>");
sb.append("<href>" + "http://maps.google.com/mapfiles/kml/pal4/icon38.png" + "</href>");
sb.append("</Icon>");
sb.append("</IconStyle>");
sb.append("</Style>");
sb.append("</Style>");
sb.append("<Placemark>");
sb.append("<name>" + "Some name" + "</name>");
sb.append("<styleUrl>" + "#defaultStyles"+ "</styleUrl>");
sb.append("<altitudeMode>" + "relativeToGround" + "</altitudeMode>");
sb.append("<Location>");
sb.append("<longitude>" + -122.3599987260313 + "</longitude>");
sb.append("<latitude>" + 47.62949781133496 + "</latitude>");
sb.append("<altitude>"+ 15.49615401024533 + "</altitude>");
sb.append("</Location>");
sb.append("<Link>");
sb.append("<href>" + "http://localhost:8080/myCompany/lib/img/dubai.jpg" + "</href>");
sb.append("</Link>");
sb.append("</Model>");
sb.append("</Placemark>");
sb.append("</Document>");
sb.append("</kml>");
return sb.toString();
}
你的错误是什么?你能缩小它吗? – ArtB 2012-02-13 12:47:57
将您的方法的kml输出粘贴到文本文件中,并很好地识别它,然后您会看到它被盗用。我看到的第一个明显的是你有一个/ Model(endtag)没有对应的starttag – Eddy 2012-02-13 19:26:01
男人tks第一,我得到了msg“kml是undefined”,我减少了我的kml只是为了测试,我得到了那个消息,我已经已经在kml interactive中测试过了,我在我的应用程序中得到了同样的kml,它在那里工作 – 2012-02-14 18:01:02