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.没有从这个代码获得,如地点,地址等 上面代码的问题是什么? 请帮忙 感谢
答案 0 :(得分:0)
如果它无效,您可以拨打谷歌提供的API
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();
}
}