2

I am querying a SQLite database for Latitude/Longitude details.

SELECT * FROM tblMain 
  where latitude > -33.866 and latitude <=-33.865 
  and longitude > 151.20 and longitude <= 151.209

I wish to give the user a range to choose for the query (1 km, 2 km etc)

How many meters are in each Latitude / Longitide so I can calculate the resolution of the query?

Ian Vink
  • 66,960
  • 104
  • 341
  • 555
  • You should check out the Great Circle formula. This should accomplish what you're trying to attempting to calculate. http://stackoverflow.com/questions/574691/mysql-great-circle-distance-haversine-formula – George Johnston Sep 08 '11 at 20:44

2 Answers2

4

You can solve this with a little bit of trigonometry and an approximation for the earths radius.

earthradius = 6371 km
distance( deg1, deg2 ) = earthradius * sin( (2pi * (deg2-deg1))/360. )

It can also be useful to remember that 1 arc second is about 30m

Andrew Walker
  • 40,984
  • 8
  • 62
  • 84
3

One degree diference in latitude is about 111.3 km, one degree diff in longitute depends on the latitude: 111.3 km * cos(lat). The precision is about 20km across europe.

Arne Burmeister
  • 20,046
  • 8
  • 53
  • 94