dimanche 5 avril 2015

Can't get address from longitude and latitude in android


Vote count:

0




I am trying to get my address from longitude and latitude , but when I am trying to do so , it doesn't work . It says W/System.err﹕ at teamtreehouse.com.stromy.MainActivity.getCompleteAddressString(MainActivity.java:163) in logcat


Here is the method I have tried



private String getCompleteAddressString() {
String strAdd = "";
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("");

for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
strAdd = strReturnedAddress.toString();
// Log.w("My Current loction address", "" + strReturnedAddress.toString());

} else {
// Log.w("My Current loction address", "No Address returned!");
}
} catch (Exception e) {
e.printStackTrace();
// Log.w("My Current loction address", "Canont get Address!");
}
return strAdd;
}


And I call it like



public void updateDisplay() {
mLocation.setText(getCompleteAddressString());
}


In getCompleteAddressString() method , I have used longitude and latitude , which I have already got from a another method and it is working fine . Both method are running withing main activity . All other things are working fine except this , how can I solve it ? what are reason of this error ?



asked 21 secs ago







Can't get address from longitude and latitude in android

Aucun commentaire:

Enregistrer un commentaire