Find file History

id title brief article sdk
Reverse Geocode a Location
This recipe shows how use the Geocoder to get an address from a latitude and longitude.


Follow these steps to reverse geocode a location.

  1. In Main.axml (or whatever layout file you wish) add the following XML.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
  1. Add a string resource named revGeocodeButtonText to Strings.Xml.
<string name="revGeocodeButtonText">Reverse Geocode Location</string>
  1. Add a click event handler for the button in the Activity’s OnCreate method.
var button = FindViewById<Button> (Resource.Id.revGeocodeButton);
button.Click += async (sender, e) => { … }

Notice that this is using an async lambda to perform the work when the button is clicked. This will cause the work to performed asynchronously and not block the UI thread.

  1. Next add the following code to the click event handler:
button.Click += async (sender, e) => {
	var geo = new Geocoder (this);
	var addresses = await geo.GetFromLocationAsync (42.37419, -71.120639, 1);

	var addressText = FindViewById<TextView> (Resource.Id.addressText);
	if (addresses.Any())
		addresses.ToList().ForEach (addr => addressText.Append (addr + System.Environment.NewLine + System.Environment.NewLine));
		addressText.Text= "Could not find any addresses.";

Running the application results in the address being displayed as shown in the screenshot above.

Additional Information

This recipe creates a Geocoder instance, which is in the Android.Locations namespace. The Geocoder calls GetFromLocationAsync with the latitude and longitude to reverse geocode. This will perform the network call asynchronously so that main UI thread is not blocked. When the result is returned, the method will return a list of addresses and continue on the UI thread. In this call 1 address is returned because that is the number passed into the third argument of the GetFromLocationAsync call. The returned address contains a variety of information about the location, including the street address.