This article illustrates the implementation of Android's address information display via the location API. Share to everyone for your reference. Specifically as follows:
The Android Locatin API allows you to display specific latitude and longitude address information through the Geocoder class. Such as:
By Geocoder Method Getfromlocation () can get the list of address objects. I only take one address result, I can take multiple, but it doesn't make much sense.
StringBuilder builder = new StringBuilder ();
Builder.append ("Northern Latitude:"). Append (This.location.getLatitude ()). Append ("\ n");
Builder.append ("N:"). Append (This.location.getLongitude ()). Append ("\ n");
try {
list<address> addresses = new Geocoder (this). Getfromlocation (
this.location.getLatitude (), This.location.getLongitude (),
3);
if (addresses.size () > 0) {Address
= addresses.get (0);
For [address address:addresses] {for
(int i = 0; i < Address.getmaxaddresslineindex (); i++) {
builder.a Ppend (Address.getaddressline (i)). Append ("\ n");
Builder.append (Address.getlocality ()). Append ("\ n");
Builder.append (Address.getpostalcode ()). Append ("\ n");
Builder.append (Address.getcountryname ());
}
// }
}
The effect is as shown in the following illustration:
I hope this article will help you with your Android program.