Reputation: 127
I want to search all records from my SQL Server database, based on some conditions
like "Near by 5 Km area", "people from my present location" (Male, Female, Both) etc.
The table structure looks like this:
So, how can I do this?
Thanks
Upvotes: 1
Views: 288
Reputation: 882
I'm afraid you'll be force to use something like google maps API for c# to count the distance.
Otherwise, maybie you have something like additional "distance from" table, but I don't think so...
In general even if you have some table with columns like Addres, Gender it's still not that easy to perform:
Distance between addresses
Solution from that answer:
public decimal calcDistance(decimal latA, decimal longA, decimal latB, decimal longB)
{
double theDistance = (Math.Sin(DegreesToRadians(latA)) *
Math.Sin(DegreesToRadians(latB)) +
Math.Cos(DegreesToRadians(latA)) *
Math.Cos(DegreesToRadians(latB)) *
Math.Cos(DegreesToRadians(longA - longB)));
return Convert.ToDecimal((RadiansToDegrees(Math.Acos(theDistance)))) * 69.09M * 1.6093M;
}
Upvotes: 0
Reputation: 29161
Have a read of my StackOverflow answer here:
Get the nearest longitude and latitude from MSSQL database table?
Basically, you can use the SQL Server geography
type, then use STDistance
.
This article includes an example, showing exactly how to use it, and also how to use Pythagorus, to calculate the distances even quicker.
Upvotes: 2