Enterprise Application Architecture with LINQ to SQL - The Code Project - Design and Architecture
October 17, 2007 — vincenthome
Contents
Via Enterprise Application Architecture with LINQ to SQL - The Code Project - Design and Architecture
Contents
Via Enterprise Application Architecture with LINQ to SQL - The Code Project - Design and Architecture
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.