Hi guys, this time I'm just having a flashback, in order to remember my thesis project which died because Google closed its Google Fusion Table service, 1 year after Google Plus closed.
Okay, no need to be long-winded, I used to wonder how to display a complete address but the data I had was only coordinates, whereas to provide complete information to users I needed to display the complete address as well. I wanted at least:
- Street or Village Name.
- City or Regency or Subdistrict.
- ZIP or Postal Code.
- A combination of the elements above.
Simply put, it's how we can cast coordinate data to complete address data, and coincidentally at that time the language I used was Java, so it turned out like this.
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(latitude, longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName(); // Only if available else return NULL
If you are a kotlin user, then it doesn't matter, Android Studio is a magic tool, so it can auto convert to kotlin, or maybe a popup still appears? well the decision is up to you. Sometimes Android Studio's auto convert is not always proper, so you as a programmer must be able to do manual debugging approaches.
If you are interested in learning more, you can read the full documentation HERE .