Section C.1. Understanding Proximity Search


C.1. Understanding Proximity Search

Proximity search works by applying the law of cosines, which calculates the distance between two points on the globe. Because the law of cosines takes into account the curvature of the earth, it is considered better than other methods, such as the Pythagorean Theorem. An abridged version of the law of cosines is as follows:

     a = sin(latitude_1) * sin(latitude_2)     b = cos(latitude_1) * cos(latitude_2) *          cos(longitude_2 - longitude_1)     c = arcos( a + b )     d = R*c

In this law, the following facts are true:

  • latitude_1, longitude_1, latitude_2, and longitude_2 are the points between which we want to measure the distance (latitude and longitude are expressed in radians)

  • R is the Earth's radius (3,963.0 in miles or 6,378.5 in kilometers)

  • d is the distance between the two points

This formula takes two latitude and longitude pairs, one for a location stored in your SQL data store, such as the address of an ATM, and one for a location provided by your end user, such as the user's current location around which she wants to find ATMs. During a proximity search, the distance is calculated between the user's current address and each business location within the specified search radius, and the results are then ordered by distance.

In the following sections, I will go through a step-by-step approach to building your own spatial proximity search using SQL Server.




Programming MapPoint in  .NET
Programming MapPoint in .NET
ISBN: 0596009062
EAN: 2147483647
Year: 2005
Pages: 136
Authors: Chandu Thota

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net