Reverse geocode a street address

How to convert latitude and longitude coordinates to a street address

PDF for offline use
Sample Code:
Related Articles:
Related APIs:

Let us know how you feel about this

Translation Quality


0/250

This recipe shows how to reverse geocode user supplied latitude and longitude coordinates into a street address by using the `Geocoder` class included in Xamarin.Forms.Maps.

Overview

The Xamarin.Forms.Maps NuGet package is used to add maps to a Xamarin.Forms app, and uses the native map APIs on each platform. This NuGet package provides the Geocoder class that converts between string addresses and latitude and longitudes.

By using the native map APIs on each platform Xamarin.Forms.Maps provides a fast, familiar maps experience for users, but means that some configuration steps are required to adhere to each platforms specific API requirements. For information about these configuration steps see Working with Maps in Xamarin.Forms.

Reverse geocoding a street address

In the code building the user interface for a page, import the Xamarin.Forms.Maps namespace and create an instance of the Geocoder class.

using Xamarin.Forms.Maps;
// ...
Geocoder geoCoder;

public ReverseGeocodePage ()
{
  InitializeComponent ();
  geoCoder = new Geocoder ();
}

Then for user supplied latitude and longitude coordinates call the GetAddressesForPositionAsync method on the Geocoder instance in order to asynchronously get a list of addresses near the position.

var position = new Position (latitude.Value, longitude.Value);
var possibleAddresses = await geoCoder.GetAddressesForPositionAsync (position);
foreach (var address in possibleAddresses)
    reverseGeocodedOutputLabel.Text += address + "\n";

Summary

This recipe shows how to reverse geocode user supplied latitude and longitude coordinates into a street address by using the Geocoder class included in Xamarin.Forms.Maps.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.