Search Wiki:
Find out how to create custom indexes for geographical data that includes latitude and longitude location information so that you can retrieve real-time data faster than ever.

Read the article online: http://msdn.microsoft.com/magazine/jj133823
Last edited May 30 2012 at 8:11 PM  by KSharkey, version 2
Comments
mscherotter wrote  Nov 18 2012 at 6:03 AM  
Compiling the code, Visual Studio finds that the Distance function is missing a ).

jmccaffrey wrote  Nov 18 2012 at 5:04 PM  
(from the author) Thanks Michael. Yes. The Distance function is missing a right paren just after lon1Radians. I botched a copy-paste. Correct is:

public static double Distance(double lat1, double lon1, double lat2, double lon2)
{
double r = 6371.0; // approx. radius of earth in km
double lat1Radians = (lat1 * Math.PI) / 180.0;
double lon1Radians = (lon1 * Math.PI) / 180.0;
double lat2Radians = (lat2 * Math.PI) / 180.0;
double lon2Radians = (lon2 * Math.PI) / 180.0;
double d = r * Math.Acos((Math.Cos(lat1Radians) *
Math.Cos(lat2Radians) *
Math.Cos(lon2Radians - lon1Radians)) +
(Math.Sin(lat1Radians) * Math.Sin(lat2Radians)));
return d;
}

Updating...
Page view tracker