I’m currently using this query to get a town inside my DB by giving a coordinate :
SELECT *
FROM citiesTable
WHERE latitude >= ? AND latitude <= ?
AND longitude >= ? AND longitude <= ?;
This code works well and do I want but sometimes the query doesn’t match anything…
So, in this case, I would put a bird distance to this query in order to get adjacent town.
Any suggestion on how can I do that ?
Searching for “distance from longitude and latitude” gave a link to http://www.movable-type.co.uk/scripts/latlong.html which specifies this code for calculating the distance:
A couple more minutes of searching led to http://www.movable-type.co.uk/scripts/latlong-db.html
That page is chock-full of information. Here’s a simple (but inefficient) solution, assuming your town is at
$lon,$latand$Ris 6371 (which is km), and finally that you want the cities to be within$radof your town: