我正在进行一个使用Java创建KML文件的项目。目前,我正在使用Micromata Labs JAK Example中的示例Java代码进行尝试。我尝试通过添加多个坐标并获取两个标记来“扩展”代码,但是我无法使其工作。请问您如何在代码中添加多个坐标、将标记放置在它们上面,并在标记之间绘制一条线。感谢您的帮助!
附注:我需要通过程序完成这个操作。我看到了他们使用DOM和XML的示例代码,但没有纯Java / JAK的示例。请指导我。
我已经做到了这一步(已更新):
kml.createAndSetDocument().withName("MyMarkers")
.createAndAddPlacemark().withName("London, UK").withOpen(Boolean.TRUE)
.createAndSetPoint().addToCoordinates(-0.126236, 51.500152);
kml.createAndSetDocument().withName("MyMarkers")
.createAndAddPlacemark().withName("Somewhere near London,UK").withOpen(Boolean.TRUE)
.createAndSetPoint().addToCoordinates(-0.129800,52.700152);
但是我知道我在某个地方做错了。请指出我正确的方向。
以下是生成的KML输出:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Document>
<name>MyMarkers</name>
<Placemark>
<name>Somewhere near London, UK</name>
<open>1</open>
<Point>
<coordinates>-0.1298,52.700152</coordinates>
</Point>
</Placemark>
</Document>
</kml>
我似乎无法再次访问文档以添加更多的地标。我该怎么做?