Distance between two points in km
-
I get from the goo angle of the LatLng point coordinates, in the same form, there's a table on the server with many lines with lat, lon. We need to select only those within a 10-km radius of the designated point.
SELECT *FROM us WHERE ...
What's the condition to There's an algorithm on the php, but I need to do it by mysql means.
function haversineGreatCircleDistance( $latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000) { // convert from degrees to radians $latFrom = deg2rad($latitudeFrom); $lonFrom = deg2rad($longitudeFrom); $latTo = deg2rad($latitudeTo); $lonTo = deg2rad($longitudeTo);
$latDelta = $latTo - $latFrom;
$lonDelta = $lonTo - $lonFrom;$angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) +
cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));
return $angle * $earthRadius;
}
-
I found it. If anyone needs it, it's miles away.
SELECT uid, ( 6371 * acos( cos( radians(50.280848) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(30.445011) ) + sin( radians(50.280848) ) * sin( radians( lat ) ) ) ) AS distance FROM users HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;