我在 String format 转换 Country Name 到 Longitude and Latitude .
为此,我使用以下 JSON web service .
https://maps.googleapis.com/maps/api/geocode/json?address=India&sensor=true
我不知道如何从那个JSON获得 Longitude and Latitude .
请 help me to get Longitude and Latitude from the above web service.
我曾尝试过下面的代码,但我不确定它是否正确:
try
{
Log.v("MAPS","Lang-Lat::1");
String myjsonstring = stringBuffer.toString();
Log.v("My JSON STRING",""+myjsonstring);
Log.v("MAPS","Lang-Lat::2");
JSONArray jsonArray = new JSONArray(myjsonstring);
Log.v("MAPS","Lang-Lat::3");
JSONObject jsonObj = null;
String status = jsonObj.getString("status");
Log.v("MAPS","Lang-Lat::4");
if (status.equals("OK"))
{
Log.v("Log Receive","Json String:::"+myjsonstring);
jsonObj = jsonArray.getJSONObject(0);
JSONObject JSONObject2=jsonObj.getJSONObject("geometry");
JSONObject JSONObject3=JSONObject2.getJSONObject("bounds");
JSONObject JSONObject4=JSONObject3.getJSONObject("northeast");
for(int i=0; i<JSONObject4.length();i++)
{
lang = JSONObject4.getDouble("lng");
lat=JSONObject4.getDouble("lat");
Log.v("Lang:",""+lang);
Log.v("Lat",""+lat);
}
}
}
catch (Exception e)
{
Log.v("Map_View::","Call JSON Exception in Getting Map--->"+e.toString());
e.printStackTrace();
}
任何帮助将不胜感激 .
先感谢您 .
1 回答
/ ************ 从地址获取经度和经度 ************* /
调用Asynctask获取纬度和经度