0

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)

Abdullah Darwish
  • 223
  • 2
  • 5
  • 17
  • What are the data types of longitude and latitude? Specifically, are you using the `geography` data type? And there are numerous questions on this site and elsewhere about lat/long calculations and "find nearest" searches, so you may want to research further and then come back with a more specific question if you still have problems. – Pondlife May 26 '12 at 20:16
  • I am using geography point (datatype) – Abdullah Darwish May 27 '12 at 08:32
  • possible duplicate of [Search nearby points from a geography column](http://stackoverflow.com/questions/10192498/search-nearby-points-from-a-geography-column) – Pondlife May 29 '12 at 06:21

1 Answers1

0

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.

Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82