错误:无法从地址解析器获取地址
问题描述:
ConnectionDetector cd = new ConnectionDetector(Healthcare.this);
isInternetPresent = cd.isConnectingToInternet();
if (isInternetPresent) {
GPSTracker gps = new GPSTracker(this);
Geocoder geoCoder = new Geocoder(Healthcare.this, Locale.getDefault());
if (gps.canGetLocation()) {
try {
latitudecur = gps.getLatitude();
longitudecur = gps.getLongitude();
Log.d("latlong",""+latitudecur+longitudecur);
List<Address> address = geoCoder.getFromLocation(latitudecur, longitudecur, 1);
Log.e("FInalAddress1",""+address.size());
## Heading ##
} catch (NullPointerException e) {
// TODO: handle exception
} catch (NumberFormatException e) {
// TODO: handle exception
} catch (IOException e) {
e.printStackTrace();
}
} else {
}
}
我在代码中写了上面的代码,但在Log.e(“FInalAddress1”,“”+ address.size()); address.getsize()得到0.没有得到像这样的代码,如地方,地址等 我的问题上面的代码是什么? 请帮助 感谢错误:无法从地址解析器获取地址
答
如果它不工作,你可以调用谷歌
JSONObject jsonObject = getJsonResponse("http://maps.google.com/maps/api/geocode/json?latlng=" + mLatitude + "," + mLogitude + "&sensor=true");
if (jsonObject != null) {
try {
JSONArray jsonArray = jsonObject.getJSONArray("results");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject addressResult = jsonArray.getJSONObject(i);
String formattedAddress = addressResult.getString("formatted_address");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
+0
谢谢,但我知道解决方案,但我想使用地理编码器 – Makvin
它需要互联网连接提供的API。你把互联网许可证明了吗? – lal
做了'latlong'打印值? – rafsanahmad007
是的,我把清单中的互联网权限,并获得经纬度 – Makvin