What does each Android.Address method return?

I am trying to figure out how to get an address component with Android SDK with class android.location.Address.

Some of the methods are very simple, others are easily understood with examples in the documentation, but some of them are completely unclear to me. Either because the documentation does not have an example, or because the example refers to the United States, which does not have the same political organization as other countries.

I searched for their meaning, but most tutorials on the Internet just use the getAddressLine(int index) method for training, and then the developer can study the rest.

  • getAdminArea() : returns the status acronym ("CA", for California)
  • getCountryCode() : returns the ISO code of the country ("JP", for Japan)
  • getCountryName() : returns the name of the country ("Spain", for ... Spain)
  • getFeatureName() : returns the name of the location, if any ("Louvre", for the museum)
  • getLocality() : returns the name of the city ("London")
  • getPostalCode() : returns the zip code ("94110", in the USA)
  • getPremises() :
  • getSubAdminArea() :
  • getSubLocality() :
  • getSubThoroughfare() :
  • getThoroughfare() : returns the street and building number ("1600 Parkway Amphitheater").

My question is what all of these methods return (and, if possible, examples).

In addition, I would like to know how to get the building number and street name separately. Parsing a Thoroughfare line doesn't seem to be that difficult, but given that in some countries the number goes up the street, while the other comes after it is best to parse the text?

+6
source share
1 answer

I did not find the full documentation for the standard that android.location.Address uses to identify and store addresses worldwide, so I made several address requests from different countries to interpret the results.

As Guillerme says, we have getAddressLine(int index) and a list of methods to retrieve each address element.

This post is not intended to explain the code, but I am posting it here for those who should see it.

 List<Address> addresses; Geocoder geocoder = new Geocoder(getActivity()); addresses = geocoder.getFromLocation(latitude, longitude, 10); if (addresses == null || addresses.isEmpty()) { // Mygeocoder is a class with a http request to google server, that replaces Geocoder, if not work addresses = MyGeocoder.getFromLocation(latitude, longitude, 10); } HashMap itemAddress; ArrayList itemList = new ArrayList<HashMap<String, String>>(); Log.d("Addresses", "" + "Start to print the ArrayList"); for (int i = 0; i < addresses.size(); i++) { itemAddress = new HashMap<String, String>(); Address address = addresses.get(i); String addressline = "Addresses from getAddressLine(): "; for (int n = 0; n <= address.getMaxAddressLineIndex(); n++) { addressline += " index n: " + n + ": " + address.getAddressLine(n) + ", "; } Log.d("Addresses: ", addressline); Log.d("Addresses getAdminArea()", "" + address.getAdminArea()); Log.d("Addresses getCountryCode()", "" + address.getCountryCode()); Log.d("Addresses getCountryName()", "" + address.getCountryName()); Log.d("Addresses getFeatureName()", "" + address.getFeatureName()); Log.d("Addresses getLocality()", "" + address.getLocality()); Log.d("Addresses getPostalCode()", "" + address.getPostalCode()); Log.d("Addresses getPremises()", "" + address.getPremises()); Log.d("Addresses getSubAdminArea()", "" + address.getSubAdminArea()); Log.d("Addresses getSubLocality()", "" + address.getSubLocality()); Log.d("Addresses getSubThoroughfare()", "" + address.getSubThoroughfare()); Log.d("Addresses getThoroughfare()", "" + address.getThoroughfare()); } 

Here are the results from latitude and longitude in Miami:

  • D / Addresses: start printing an ArrayList
  • D / Addresses :: Addresses from getAddressLine (): index n: 0: 7500 SW 120th St, index n: 1: Miami, Florida 33156, index n: 2: EE. UU.,
  • D / Addresses getAdminArea (): Florida
  • D / Addresses getCountryCode (): US
  • D / Addresses getCountryName (): Estados Unidos
  • D / Addresses getFeatureName (): 7500
  • D / GetLocality () Addresses: Miami
  • D / Addresses getPostalCode (): 33156
  • D / Addresses getPremises (): null
  • D / Addresses getSubAdminArea (): null
  • D / Addresses getSubLocality (): null
  • D / Addresses getSubThoroughfare (): 7500
  • D / Addresses getThoroughfare (): SW 120th St
  • D / Addresses :: Addresses from getAddressLine (): index n: 0: Pinecrest, Florida, index n: 1: EE. UU.,
  • D / Addresses getAdminArea (): Florida
  • D / Addresses getCountryCode (): US
  • D / Addresses getCountryName (): Estados Unidos
  • D / Addresses getFeatureName (): Pinecrest
  • D / Addresses getLocality (): Pinecrest
  • D / Addresses getPostalCode (): null
  • D / Addresses getPremises (): null
  • D / Addresses getSubAdminArea (): Condado de Miami-Dade
  • D / Addresses getSubLocality (): null
  • D / Addresses getSubThoroughfare (): null
  • D / Addresses getThoroughfare (): null
  • D / Addresses :: Addresses from getAddressLine (): index n: 0: Miami, Florida 33156, index n: 1: EE. UU.,
  • D / Addresses getAdminArea (): Florida
  • D / Addresses getCountryCode (): US
  • D / Addresses getCountryName (): Estados Unidos
  • D / Addresses getFeatureName (): 33156
  • D / GetLocality () Addresses: Miami
  • D / Addresses getPostalCode (): 33156
  • D / Addresses getPremises (): null
  • D / Addresses getSubAdminArea (): null
  • D / Addresses getSubLocality (): null
  • D / Addresses getSubThoroughfare (): null
  • D / Addresses getThoroughfare (): null
  • D / Addresses :: Addresses from getAddressLine (): index n: 0: Condado de Miami-Dade, index n: 1: Florida, index n: 2: EE. UU.,
  • D / Addresses getAdminArea (): Florida
  • D / Addresses getCountryCode (): US
  • D / Addresses getCountryName (): Estados Unidos
  • D / Addresses getFeatureName (): Condado de Miami-Dade
  • D / Addresses getLocality (): null
  • D / Addresses getPostalCode (): null
  • D / Addresses getPremises (): null
  • D / Addresses getSubAdminArea (): Condado de Miami-Dade
  • D / Addresses getSubLocality (): null
  • D / Addresses getSubThoroughfare (): null
  • D / Addresses getThoroughfare (): null
  • D / Addresses :: Addresses from getAddressLine (): index n: 0: Florida, index n: 1: EE. UU.,
  • D / Addresses getAdminArea (): Florida
  • D / Addresses getCountryCode (): US
  • D / Addresses getCountryName (): Estados Unidos
  • D / Addresses getFeatureName (): Florida
  • D / Addresses getLocality (): null
  • D / Addresses getPostalCode (): null
  • D / Addresses getPremises (): null
  • D / Addresses getSubAdminArea (): null
  • D / Addresses getSubLocality (): null
  • D / Addresses getSubThoroughfare (): null
  • D / Addresses getThoroughfare (): null
  • D / Addresses :: Addresses from getAddressLine (): index n: 0: Estados Unidos,
  • D / Addresses getAdminArea (): null
  • D / Addresses getCountryCode (): US
  • D / Addresses getCountryName (): Estados Unidos
  • D / Addresses getFeatureName (): Estados Unidos
  • D / Addresses getLocality (): null
  • D / Addresses getPostalCode (): null
  • D / Addresses getPremises (): null
  • D / Addresses getSubAdminArea (): null
  • D / Addresses getSubLocality (): null
  • D / Addresses getSubThoroughfare (): null
  • D / Addresses getThoroughfare (): null

In the above result sets, we see that we gave 6 Geocoder result sets, if we analyze, this is a multi-level location from the exact address with all its attributes, therefore only in the country. It seems that each layer is a different map, a map of individual countries, a map of states and countries, until a map for routes and streets, and each set of geocoding requests are received from each map.

I consulted a point in a village in Colombia, Geocoder gave me 5 result sets. Let it analyze only the first set, compared with the previous one.

  • D / Addresses: start printing an ArrayList
  • D / Addresses :: Addresses from getAddressLine (): index n: 0: Calle 34 # 36-2 a 36-100, index n: 1: Palmira, Valle del Cauca, index n: 2: Colombia,
  • D / Addresses getAdminArea (): Valle del Cauca
  • D / Addresses getCountryCode (): CO
  • D / Addresses getCountryName (): Colombia
  • D / Addresses getFeatureName (): 362-36100
  • D / Addresses getLocality (): Palmira
  • D / Addresses getPostalCode (): null
  • D / Addresses getPremises (): null
  • D / Addresses getSubAdminArea (): null
  • D / Addresses getSubLocality (): null
  • D / Addresses getSubThoroughfare (): 362-36100
  • D / Addresses getThoroughfare (): Calle 34

The only difference is that these results do not have PostalCode and SubAdminArea.

Now I consulted a point in Egypt:

  • D / Addresses: start printing an ArrayList
  • D / Addresses :: Addresses from getAddressLine (): index n: 0: حارة عابدين, index n: 1: الزيتون البحرية, index n: 2: الزيتون, index n: 3: Gobernación de El Cairo, index n: 4: Egipto ,
  • D / Addresses getAdminArea (): null
  • D / Addresses getCountryCode (): EG
  • D / Addresses getCountryName (): Egipto
  • D / Addresses getFeatureName (): حارة عابدين
  • D / Addresses getLocality (): null
  • D / Addresses getPostalCode (): null
  • D / Addresses getPremises (): null
  • D / Addresses getSubAdminArea (): null
  • D / Addresses getSubLocality (): null
  • D / Addresses getSubThoroughfare (): null
  • D / Addresses getThoroughfare (): حارة عابدين

There are many differences in Egypt; for example, getMaxAddressLine() gives 5 results, Colombia and the USA - only 3 results. Changing the order of a country's location in getAddressLine() in Colombia and the USA is in getAddressLine(2) Egypt getAddressLine(4) . getLocality() must have a Cairo city, but not persisted.

In conclusion, the list of geocoding results is an adaptation for the system in each country, and there is no update.

It already depends on the application being developed, in order to optimize the results shown in Geocoder, if we show the user where he is, it is better to use getAddressLine() , but if we need a country in the database, you should use getCountry() . If you want to receive more detailed information, we must determine the system of each country or region and develop for each.

+8
source

All Articles