I have venues in the database that I store with their latitude and longitude.
I also have the logged in user's latitude and longitude.
I'm developing a function that will allow them to find venues within any given measurement, say 20 miles.
Is it possible to find the outermost lat and long of say 20 miles from the user's lat and long and then somehow write a query to find venues within the circle of distance in MySQL?
Thanks.
I found a working PHP function:
function getDistanceBetweenPoints($latitude1, $longitude1, $latitude2, $longitude2, $unit = 'Mi') {
$theta = $longitude1 - $longitude2;
$distance = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
$distance = acos($distance);
$distance = rad2deg($distance);
$distance = $distance * 60 * 1.1515; switch($unit) {
case 'Mi': break; case 'Km' : $distance = $distance * 1.609344;
}
return (round($distance,2));
}
Thought this may help others.
I use this (ported to Objective-C from javascript) - lots of great location equations expressed in javascript http://www.movable-type.co.uk/scripts/latlong.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With