出口KML數據我正在開發一個RESTful Web服務其中的一個特徵是,該服務將獲取的用戶當前位置,並顯示他附近的餐館。如何通過/從Java
直到現在,我從有關谷歌地圖API的得到JSON數據完成這個任務,並分析相關數據,並將其傳遞到客戶端/消費者。 但是現在不用文字/ JSON數據,我想通過KML附近餐館的數據,這樣消費者可以根據地圖而不是簡單的文字在表格中顯示它。
我創造我的KML數據similiar方式follwing代碼執行:
package de.micromata.jak.examples;
import java.io.File;
import java.io.FileNotFoundException;
import de.micromata.opengis.kml.v_2_2_0.Document;
import de.micromata.opengis.kml.v_2_2_0.Folder;
import de.micromata.opengis.kml.v_2_2_0.Icon;
import de.micromata.opengis.kml.v_2_2_0.Kml;
import de.micromata.opengis.kml.v_2_2_0.Placemark;
import de.micromata.opengis.kml.v_2_2_0.Style;
/**
* This example generates a KML file with a placemark and a chart for each continent. The chart is generated with the Google Chart API and
* show the area (surface of the earth) of each continent.
*
* Google Chart API example: http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World
*/
public class Example1 {
public static void main(String[] args) throws FileNotFoundException {
final Kml kml = new Kml();
Document doc = kml.createAndSetDocument().withName("JAK Example1").withOpen(true);
// create a Folder
Folder folder = doc.createAndAddFolder();
folder.withName("Continents with Earth's surface").withOpen(true);
// create Placemark elements
createPlacemarkWithChart(doc, folder, 93.24607775062842, 47.49808862281773, "Asia", 30);
createPlacemarkWithChart(doc, folder, 19.44601806124206, 10.13133611111111, "Africa", 20);
createPlacemarkWithChart(doc, folder, -103.5286299241638, 41.26035225962401, "North America", 17);
createPlacemarkWithChart(doc, folder, -59.96161780270248, -13.27347674076888, "South America", 12);
createPlacemarkWithChart(doc, folder, 14.45531426360271, 47.26208181151567, "Europe", 7);
createPlacemarkWithChart(doc, folder, 135.0555272486322, -26.23824399654937, "Australia", 6);
// print and save
kml.marshal(new File("advancedexample1.kml"));
}
/**
* The createPlacemarkWithChart()-method generates and set a placemark object, with the given statistical data . The Icon and Style
* objects (color and size of the text and icon) are saved to the root element. The placemark is created and set to the given folder.
*
* @param document structure of the KML file
* @param folder to add continent
* @param longitude of the continent
* @param latitude of the continent
* @param continentName or name of the placemark
* @param coveredLandmass in percent
*/
private static void createPlacemarkWithChart(Document document, Folder folder, double longitude, double latitude,
String continentName, int coveredLandmass) {
int remainingLand = 100 - coveredLandmass;
Icon icon = new Icon()
.withHref("http://chart.apis.google.com/chart?chs=380x200&chd=t:" + coveredLandmass + "," + remainingLand + "&cht=p&chf=bg,s,ffffff00");
Style style = document.createAndAddStyle();
style.withId("style_" + continentName) // set the stylename to use this style from the placemark
.createAndSetIconStyle().withScale(5.0).withIcon(icon); // set size and icon
style.createAndSetLabelStyle().withColor("ff43b3ff").withScale(5.0); // set color and size of the continent name
Placemark placemark = folder.createAndAddPlacemark();
// use the style for each continent
placemark.withName(continentName)
.withStyleUrl("#style_" + continentName)
// 3D chart imgae
.withDescription(
"<![CDATA[<img src=\"http://chart.apis.google.com/chart?chs=430x200&chd=t:" + coveredLandmass + "," + remainingLand + "&cht=p3&chl=" + continentName + "|remaining&chtt=Earth's surface\" />")
// coordinates and distance (zoom level) of the viewer
.createAndSetLookAt().withLongitude(longitude).withLatitude(latitude).withAltitude(0).withRange(12000000);
placemark.createAndSetPoint().addToCoordinates(longitude, latitude); // set coordinates
}
}
現在,我應該怎麼通過這個生成的KML數據,以我的消費?
以前,對於JSON數據,我創建了ArrayList並將數據放入其中,最後將ArrayList的對象返回給使用者。但我不知道如何使用KML數據完成相同的任務。
任何幫助將不勝感激。
請提出任何其他更好的辦法解決上述問題。
謝謝!
什麼是背後downvote原因在地圖上? –