Finding Cities within 'X' Kilometers (or Miles)
Posted
by Mike Curry
on Stack Overflow
See other posts from Stack Overflow
or by Mike Curry
Published on 2009-04-30T20:43:13Z
Indexed on
2010/06/07
14:32 UTC
Read the original article
Hit count: 304
This may or may not be clear, leave me a comment if I am off base, or you need more information. Perhaps there is a solution out there already for what I want in PHP.
I am looking for a function that will add or subtract a distance from a longitude OR latitude value.
Reason: I have a database with all Latitudes and Longitudes in it and want to form a query to extract all cities within X kilometers (or miles). My query would look something like this...
Select * From Cities Where (Longitude > X1 and Longitude < X2) And (Latitude > Y1 and Latitude < Y2)
Where X1 = Longitude - (distance)
Where X2 = Longitude + (distance)
Where Y1 = Latitude - (distance)
Where Y2 = Latitude + (distance)
I am working in PHP, with a MySql Database.
Open to any suggestions also! :)
© Stack Overflow or respective owner