I have a table called Places, every record in this table have its longitude and latitude.
I want to search on this table to find the places near by specific long and lat (Assume the radius of the nearby circle is 25 KM)
I have a table called Places, every record in this table have its longitude and latitude.
I want to search on this table to find the places near by specific long and lat (Assume the radius of the nearby circle is 25 KM)
As you have a given distance to limit your search, your question is a little different with question those ask to find nearest points (without limitation). I have invented two formula which simplifies the distance calculation to degrees difference. These formula is just fitting the earth shape not any other spherical shape:
The following one shows how many Kilometers is surrounded in 1 degree of Longitude around a given latitude:
LongDistanceFactor = − 0.0114 * (lat)^2 − 0.2396(lat) + 112.57
and the second one shows how many kilometers is surrounded in 1 degree of latitude around a given latitude:
LatDistanceFactor = 0.0139(lat) + 110.51
So for given 25Km around the (lat,lng) you just need to find points which their lat is between lat ± (25/LatDistanceFactor)
and long between lng ± (25/LongDistanceFactor)
Edit: As I am using ± for both Lat and Lng, the target area would be a square with length of 50Km for each side. If you insist on a circular area, you may make a scond round calculation on first series of result with real formula of points distance and omit those are not in your circle.