i want the users on my site to be able to search for other users within a certain distance. e.g 'find all users within [5] miles'. I have some code which does this "as the crow flies" but I want to be able to find the actual distance including roads. I know that i'd need a third party tool to do this but i'm not sure what to use. Does google maps api have this function? My code at the moment:
$results = $members->prepare("SELECT users.fname, users.lname, activate.profession, activate.town, ROUND((3958.75 * ACOS(SIN(? / 57.2958)*SIN(uk_postcodes.latitude / 57.2958)+COS(? / 57.2958)*COS(uk_postcodes.latitude / 57.2958)*COS(uk_postcodes.longitude / 57.2958 - ? / 57.2958))), 1) as distance FROM uk_postcodes JOIN activate on activate.outward = uk_postcodes.postcode and activate.userid != ? JOIN users on users.user_id = activate.userid WHERE (3958.75 * ACOS(SIN(? / 57.2958)*SIN(uk_postcodes.latitude / 57.2958)+COS(? / 57.2958)*COS(uk_postcodes.latitude / 57.2958)*COS(uk_postcodes.longitude / 57.2958 - ? / 57.2958))) <= ?");
$lat = $_POST['latitude'];
$long = $_POST['longitude'];
$results->bind_param('ssssssss', $lat, $lat, $long, $_SESSION['token'], $lat, $lat, $long, $_POST['distance']);
$results->execute();
Any help is appreciated, thanks.