A New Internet Library: Add Your Website/Blog or Suggest A Website/Blog to our Free Web Directory http://anil.myfunda.net.

Its very simple, free and SEO Friendly.
Submit Now....

Saturday, December 27, 2008

Reverse GEO lookup in C#

Google’s maps API now supports reversed GEO lookup which allows you to find an address based on geo coordinates.  All you need is a latitude, a longitude and this handy method:

private const string endPoint = "http://maps.google.com/maps/geo?q={0},{1}&output=xml&sensor=true&key=YOURKEY";

 

private static string GetAddress(double latitude, double longitude)

{

  string lat = latitude.ToString(CultureInfo.InvariantCulture);

  string lon = longitude.ToString(CultureInfo.InvariantCulture);

  string url = string.Format(endPoint, lat, lon);

 

  using (WebClient client = new WebClient())

  {

    string xml = client.DownloadString(url);

    XmlDocument doc = new XmlDocument();

    doc.LoadXml(xml);

 

    XmlNode node = doc.ChildNodes[1].FirstChild.ChildNodes[2].ChildNodes[0];

    return node.InnerText;

  }

}

It returns the address as a string.



Source Click Here.

No comments:

Post a Comment

Post your comments here:

Originals Enjoy