My application using a GeoCoder keeps returning the string to true. here is the code I have.
public boolean address(){
Geocoder geoCoder =
new Geocoder
(getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(LocationManagerHelper.getLatitude()/1E6, LocationManagerHelper.getLongitude()/1E6, 1);
String addes = "";
if (addresses.size() > 0)
{
for (int i=0; i<addresses.get(0).getMaxAddressLineIndex();
i++)
addes += addresses.get(0).getAddressLine(i) + "\n";
}
}
catch (IOException e) {
e.printStackTrace();
}
return true;
}
and I call that into a text view.
add.append(""+ address()
+ '\n');
it works somewhat except for it doesn’t show the address and instead shows true
can any one tell me why this is?
thanks.
You need to initialize the result
Stringvariable outside thetryblock, then change the method’s return type toStringand indeed return the resultStringvariable after having augmented it with the lines from the address.But, really, this is basic Java programming, so before delving into a framework such as Android I would heartily suggest you learn the language first.