Affiliate links on Android Authority may earn us a commission.Learn more.
How to get Location address in an Android app
July 30, 2025
In previous tutorials, we have discussedhow to get location data, as well as using location data to implement a simple device location tracking systemusing the ThingSpeak API. For this tutorial, we are going to use theGeocoderclass to translate a given address into its latitude and longitude values (geocoding), and also translate a latitude and longitude value into an address (reverse geocoding).
Preparation
FromWikipedia, Geocoding uses a description of a location, such as a postal address or place name, to find geographic coordinates. Reverse geocoding, on the other hand, uses geographic coordinates to find a description of the location.
A geocoder is either a piece of software or a service that implements a geocoding process. The Android API contains a Geocoder class that can use either a location name or a location’s latitude and longitude values to get further details about an address (it can perform both forward and reverse geocoding). The returned address details include address name, country name, country code, postal code and more.

App Layout
Our app is going to use both forward and reverse geocoding to get location address, and the app layout reflects this. The layout contains two EditTexts for Latitude and Longitude respectively, and an EditText for address name input. Beneath these, we have two RadioButtons, to select if we are fetching an address using the location’s latitude/longitude values, or using the address name. There is a Button, that begins the geocoding lookup when clicked, a ProgressBar, to show the user that the lookup task is running in the background, and a TextView to show the result received.
Fetching the Address
Geocoder has two methods for fetching an Address, getFromLocation(), which uses latitude and longitude, and getFromLocationName(), which uses the location’s name. Both methods return a list ofAddressobjects. An Address contains information like address name, country, latitude and longitude, whereasLocationcontains latitude, longitude, bearing and altitude among others. Remember that the Geocoder methods above block the thread they are executed in, and should never be called from the app’s UI thread.
To perform a long running task in the background, we can use anAsyncTask. However, the AsyncTask is not recommended for operations like the Geocoder lookup, because it can take a potentially long time to return. AsyncTask’s should be used for comparatively shorter operations. While we can (and did) use the AsyncTask, as per the Android developer recommendations and best practices, we would use anIntentService. An IntentService extends Service, and operations run in it can take as long as necessary. An IntentService holds no reference to the Activity it was started from, and so, the activity can be rebuilt (like when the device is rotated), without affecting the IntentService’s tasks, unlike the AsyncTask. (NB: We actually used an AsyncTask, and it worked just as well. As a bonus, the activity, using an AsyncTask isavailable in the githubproject as MainActivityWithAsyncTask)

Using the IntentService
We extend IntentService and define GeocodeAddressIntentService. An IntentService is started much like an Activity. We build an Intent, and start the service by calling Context.startService() method.
Before defining the class, we include our GeocodeAddressIntentService in the AppManifest. Don’t forget to also include the INTERNET permission. In my case, while developing/testing on a Nexus 5 Lollipop device, the network calls just silently failed prior to including the INTERNET permission. So, if you do not get any response, first confirm that you have requested the INTERNET permission.

To use our IntentService, we must implement the onHandleIntent(Intent) method. This is the entry point for IntentService’s, much like the onCreate() is the entry point for Activity’s. In the code snippet below, take notice of the ResultReceiver object. When your IntentService has completed it’s task, it should have a way to send the results back to the invoking Activity. That is where the ResultReceiver comes in, and we’ll discuss it’s implementation in a bit.
The code snippet below contains the actual forward or reverse geocoding lookup calls. We determine if the search uses location name, or location latitude/longitude values, and call the appropriate method. If using location name, we call the Geocoder.getFromLocationName() method, and if using latitude/longitude, we call Geocoder.getFromLocation() method. You can specify a maximum number of addresses to be returned. In our sample, we request for a maximum of one (1) address. Note that an address name can refer to more than one location, spread across multiple countries. In a production app, you might want to fetch more than one, and have an algorithm determine which is the most likely required address.

deliverResultToReceiver is a simple method, that handles returning the results of the operation to the invoking Activity, through the ResultReceiver.
We implemented the ResultReceiver as an inner class in the MainActivity.
Starting the IntentService is pretty similar to starting a new Activity. We build an Intent, put in the necessary Extras, and call Context.startService(Intent). The Extras we bundle in the Intent is dependent on if we are performing a forward or reverse lookup.
Conclusion
While it is all well and good tracking a user’s location, for your app to truly amaze, showing users an address name for a given location will almost always be more useful than the corresponding latitude and longitude values.
The complete source code isavailable on GitHub, and can be forked, downloaded, copied and used as desired.
If you followed our previous tutorials onusing the ThingSpeak API to track a device’s location, andhow to get and use an Android device’s location, attempt to integrate geocoding and get location address in both apps. Have fun coding, and share your challenges and successes in the comments below.
Thank you for being part of our community. Read ourComment Policybefore posting.