Click here to Skip to main content
14,299,664 members

Using reverse geocoding to find an address

Rate this:
5.00 (6 votes)
Please Sign up or sign in to vote.
5.00 (6 votes)
20 Jul 2011CPOL
The post shows how to use the Geocode API in order to make an address lookup for a given location.


Making a Reverse Geocoding to Find an Address

I had a request from a colleague of mine to help him with a geocoding problem. The colleague needed to find an address by a given latitude and longitude which were supplied by a SmartPhone consumer. The example in this post will show you how you can use the Google Geocoding API in order to achieve that using C#.

Reverse Geocoding (Address Lookup)

Geocoding refers to translating an address into its location or coordinates. The reverse of it is address lookup which occurs when you have the map location and you want to get an address out of it. In today’s mobile development, it is very common to use SmartPhone built-in GPS’s in order to do geocoding and reverse geocoding. When you want to make a geocoding request, you can use Google’s geocode service in order to make location queries. When you want to make a geocode query, you will have to send an HTTP request to in XML or JSON format and a bunch of parameters in order to get your desired information. For further reading about making geocode requests, go to the Google Geocoding API documentation.

Reverse Geocoding Example

Here is a console application example of using reverse geocoding in order to find an address:

class Program
  static string baseUri = "" + 

  static void Main(string[] args)
    RetrieveFormatedAddress("51.962146", "7.602304");

  public static void RetrieveFormatedAddress(string lat, string lng)
    string requestUri = string.Format(baseUri, lat, lng);

    using (WebClient wc = new WebClient())
      wc.DownloadStringCompleted += 
        new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
      wc.DownloadStringAsync(new Uri(requestUri));

  static void wc_DownloadStringCompleted(object sender, 
                 DownloadStringCompletedEventArgs e)
    var xmlElm = XElement.Parse(e.Result);

    var status = (from elm in xmlElm.Descendants()
                  where elm.Name == "status"
                  select elm).FirstOrDefault();
    if (status.Value.ToLower() == "ok")
      var res = (from elm in xmlElm.Descendants()
                 where elm.Name == "formatted_address"
                 select elm).FirstOrDefault();
      Console.WriteLine("No Address Found");

As you can see, I use a WebClient object to make a request to the Google Geocoding API with latitude and longitude parameters. The returned string is in XML format (but can be in JSON also), which might look like:

    <formatted_address>1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA</formatted_address>
      <long_name>Amphitheatre Pkwy</long_name>
      <short_name>Amphitheatre Pkwy</short_name>
      <long_name>Mountain View</long_name>
      <short_name>Mountain View</short_name>
      <long_name>San Jose</long_name>
      <short_name>San Jose</short_name>
      <long_name>Santa Clara</long_name>
      <short_name>Santa Clara</short_name>
      <long_name>United States</long_name>

I use LINQ to XML in order to check the response status, and if it’s OK, I retrieve the formatted address value. Pay attention that I make an asynchronous request since I need to relay on a third party server (which is the Google Geocoding API in my example).


The post shows how to use the Geocode API in order to make an address lookup for a given location. I hope it will help you when you need to implement such a thing.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Gil Fink
Technical Lead sparXys
Israel Israel
Gil Fink is a web development expert and ASP.Net/IIS Microsoft MVP. He is the founder and owner of sparXys. He is currently consulting for various enterprises and companies, where he helps to develop Web and RIA-based solutions. He conducts lectures and workshops for individuals and enterprises who want to specialize in infrastructure and web development. He is also co-author of several Microsoft Official Courses (MOCs) and training kits, co-author of "Pro Single Page Application Development" book (Apress) and the founder of Front-End.IL Meetup. You can read his publications at his website:

Comments and Discussions

QuestionAnyother api's than googles Pin
Member 1026692318-Sep-13 3:27
memberMember 1026692318-Sep-13 3:27 
AnswerRe: Anyother api's than googles Pin
Gil Fink18-Sep-13 23:42
memberGil Fink18-Sep-13 23:42 
QuestionGetting Error as System.Reflection.TargetInnovationException Pin
Vijay Jangam8-Jun-13 1:53
memberVijay Jangam8-Jun-13 1:53 
GeneralMy vote of 5 Pin
kaliprasad12325-Jan-13 0:20
memberkaliprasad12325-Jan-13 0:20 
Questionreverse geocoding api Pin
Member 158083319-Mar-12 3:45
memberMember 158083319-Mar-12 3:45 
GeneralMy vote of 5 Pin
athalyeakshay26-Dec-11 20:20
memberathalyeakshay26-Dec-11 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 20 Jul 2011

Tagged as


11 bookmarked