我正在创建一个应用程序,我必须发布到此网址:Url to get KML
根据本教程,url应该返回一个KML文件:
但是当我点击网址时,我收到一个 HTML 文件作为回复,很难解析而且没用。
我的源代码是:
//Calling function to get the response KML
getKmlFromUrl("https://maps.google.com/maps?saddr=22.583375060000,88.434077990000&daddr=22.491368100000,88.348189300000&ie=UTF8&0&om=0&output=kml");
//这是获取KML文件并在logcat中显示它的函数 void getKmlFromUrl(String urlString){ String kml = null;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
makeAToast("URL:"+urlString);
HttpPost httpPost = new HttpPost(urlString);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
kml = EntityUtils.toString(httpEntity);
System.out.println("KML: "+kml);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// // return XML
// // return xml;
}
完成所有这些操作后,我没有收到 KML 响应,而是收到 HTML 响应。响应(在logcat中)就在这里:
我哪里错了?
答案 0 :(得分:2)
不再使用KML响应,google返回JSON或XML, 检查以下链接: https://developers.google.com/places/documentation/