How to convert a street address to longitude and latitude (geocoding) via web services « Jim 2.0’s Blog


string geocoderUri = string.Format(
    “http://rpc.geocoder.us/service/rest?address={0},{1},{2}”,
    street, city, state);
XmlDocument geocoderXmlDoc = new XmlDocument();
geocoderXmlDoc.Load(geocoderUri);
XmlNamespaceManager nsMgr =
    new XmlNamespaceManager(geocoderXmlDoc.NameTable);
nsMgr.AddNamespace(“geo”,
    @”http://www.w3.org/2003/01/geo/wgs84_pos#”);

string sLong = geocoderXmlDoc.DocumentElement.SelectSingleNode(
        @”//geo:long”, nsMgr).InnerText;
string sLat = geocoderXmlDoc.DocumentElement.SelectSingleNode(
        @”//geo:lat”, nsMgr).InnerText;

double latitude = Double.Parse(sLat);
double longitude = Double.Parse(sLong);

Console.WriteLine(“Lat: “ + latitude + ” Lon: “ + longitude);

 

Result:

Lat: 41.947372 Lon: -87.655788

 

Once you have the coordinates, you can perform radius searching. Troy DeMonbreun provides an example of how to calculate the distance between two geographic coordinates using a SQL Server UDF (User Defined Function). The GeoCoder.us blog also discusses how to calculate distances using two geographic coordinates.

Via How to convert a street address to longitude and latitude (geocoding) via web services « Jim 2.0’s Blog

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s