Posted by : Jebastin Thursday 19 December 2013

The following C# Code is used to get the Latitude and Longitude Co-Ordinates of a particular place anywhere in the World using the Address or Zip-code. To get the Latitude and Longitude Co-Ordinates using Address, call the function like this, getLatLong("Briarwood, NY 11435-2694",""). To get the Latitude and Longitude Co-Ordinates using the Zip-code, call the function like this, getLatLong("","11435").
  1. public string getLatLong(string Address, string Zip)
  2. {
  3.     string latlong = "", address = "";
  4.     if (Address!=string.Empty)
  5.     {
  6.         address = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + Address + "&sensor=false";
  7.     }
  8.     else
  9.     {
  10.         address = "http://maps.googleapis.com/maps/api/geocode/xml?components=postal_code:" + Zip.Trim() + "&sensor=false";
  11.     }
  12.     var result = new System.Net.WebClient().DownloadString(address);
  13.     XmlDocument doc = new XmlDocument();
  14.     doc.LoadXml(result);
  15.     XmlNodeList parentNode = doc.GetElementsByTagName("location");
  16.     var lat = "";
  17.     var lng = "";
  18.     foreach (XmlNode childrenNode in parentNode)
  19.     {
  20.         lat = childrenNode.SelectSingleNode("lat").InnerText;
  21.         lng = childrenNode.SelectSingleNode("lng").InnerText;
  22.     }
  23.     latlong = Convert.ToString(lat) + "," + Convert.ToString(lng);
  24.     return latlong;
  25. }

{ 4 comments... read them below or Comment }

  1. hello, is this paid service or free. it worked for a while then stopped. how can i use it again ?? please let me know. thanks

    ReplyDelete
    Replies
    1. Hello Sourab,

      It's a free service only but with some limitations.

      Usage Limits for the users of the free API:
      2,500 requests per 24 hour period.
      5 requests per second.

      Reference: https://developers.google.com/maps/documentation/geocoding/

      Delete

Link To This Post/Page

Spread The Word

Add this button to your blog:
JJ Technology Solutions

Blog Archive

Trackers

eXTReMe Tracker
facebook

- Copyright © JJ Technology Solutions - Powered by Source Code Solutions -