我在我的android应用程序中使用google place api Web Service,我是android新手,无法从api中读取JSON
结果,我打印了这个结果
{
"location": {
"lng": -73.9834889,
"lat": 40.7724641
}
}
和
{
"viewport": {
"southwest": {
"lng": -74.03514899999999,
"lat": 40.698078
},
"northeast": {
"lng": -73.90331300000001,
"lat": 40.820045
}
},
"location": {
"lng": -73.9712488,
"lat": 40.7830603
}
}
当我写这个代码
JSONObject dataObj = new JSONObject(response);
String status = dataObj.getString("status");
Log.i("status",status);
if (status.equals("OK")) {
JSONObject jsonArray =dataObj.getJSONObject("results");
Log.i("result",""+jsonArray);
JSONArray aa=dataObj.getJSONArray("results");
Log.i("resultssss",""+aa);
ArrayList<Mosque> mosque = new ArrayList<Mosque>();
for (int i = 0; i < aa.length(); i++) {
JSONObject jsonObject = aa.getJSONObject(i);
String geometry=jsonObject.getString("geometry");
Log.i("geometry",geometry);
以下是可能对您有用的链接。。
从谷歌地图获取JSON坐标
第二个链接链接可能会从JSON中获取详细信息。。http://www.tutorialspoint.com/android/android_json_parser.htm
希望它能帮助你D
您可以解析google places api响应并提取Latitude和Longitude,如下所示。
try {
JSONObject jObject = new JSONObject(response);
JSONArray jResults = jObject.getJSONArray("results");
for (int j = 0; j < jResults.length(); j++) {
JSONObject jPlaceObj = jResults.getJSONObject(j);
JSONObject jGeometry = jPlaceObj.getJSONObject("geometry");
JSONObject jLocation = jGeometry.getJSONObject("location");
String lat = jLocation.getString("lat");
String lng = jLocation.getString("lng");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
JSONObject jObject = new JSONObject(response);
JSONArray jResults = jObject.getJSONArray("results");
JSONObject jPlaceObj = jResults.getJSONObject(0);
JSONObject jGeometry = jPlaceObj.getJSONObject("geometry");
JSONObject jLocation = jGeometry.getJSONObject("location");
String lat = jLocation.getString("lat");
String lng = jLocation.getString("lng");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}