Reverse Geocoding in Windows Phone 8

This is a support post for the Inside Windows Phone show on location and mapping in Windows Phone 8 published here.

Reverse geocoding is the process of getting an address from a latitude/longitude pair. With Windows Phone, this process is not only easy, it works in conjunction with the offline mapping capability so that developers can query addresses from a geocoordinate even when there is no data signal available.

The process is extremely straightforward: Add the namespace

 using Microsoft.Phone.Maps.Services;

And create a new ReverseGeocodeQuery, give it a valid GeoCoordinate and set up the an event handler to manage the result.

 ReverseGeocodeQuery reverseGeocode = new ReverseGeocodeQuery();
reverseGeocode.GeoCoordinate = new GeoCoordinate(47.60887, -122.34094);
reverseGeocode.QueryCompleted += reverseGeocode_QueryCompleted;
reverseGeocode.QueryAsync();

Then in our event handler we will get a result (or list of possible results) back as a MapAddress object.

 void reverseGeocode_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
    MapAddress geoAddress = e.Result[0].Information.Address;           
}

This object will contain a nice helpful set of properties that we can then use to construct a valid address.

image 

Comments

  • Anonymous
    June 29, 2013
    Hi, I always get e.Result.Count as zero. I am testing using window phone emulator WVGA 512MB.

  • Anonymous
    March 01, 2014
    Are you sure about the part with the no data signal available? I get an empty list in the Result when I disconnect from internet.

  • Anonymous
    May 15, 2014
    @rox You need to install offline maps.