I am little bit confused about following problem & their solutions:
i have 2 tables users
& userfriends
having following structure
users
userid lat long
userfriends
userid friendid
so in users table i have lat & long of all the users & in userfriends i have list of friends for each user. Now i want to calculate nearby users (distance) so my friend told me to use mongodb which have fast performance. But i found another function which i can use in stored procedure in mysql
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if ($unit == "K") {
return ($miles * 1.609344);
} else if ($unit == "N") {
return ($miles * 0.8684);
} else {
return $miles;
}
}
So basically i want my distance calculation faster & quick. So can somebody tell me am i correct in my way or i need to send needed data (lat & long of users friends) to mongodb & calculate & mongodb will return results to my database (MySQL)?