- ( , ).
. :
distLat = abs(userLat - placeLat)
distLong = abs(userLong - placeLong)
, . :
distance = squareRoot(distLat * distLat + distLong * distLong)
, - , .
MySQL, , :
SELECT * FROM places ORDER BY MIN(SQRT((p.latitude - userLatitude) * (p.latitude - userLatitude) + (p.longitude - userLongitude) * (p.longitude - userLongitude))) LIMIT 1
, , , . .
, . MySQL- , MySQL 5.6. ST_DISTANCE, - , , . , MySQL 5.6, , ST_DISTANCE, , , , "" .
. : http://www.plumislandmedia.net/mysql/haversine-mysql-nearest-loc
OP, , .
, , . .
, , : 40.704391, -73.994675.
:
sqrt((40.704391 - 40.689167)^2 + (-73.994675 - -74.044444)^2) = 0.052045399
( 40.7179666, -73.9670125), :
sqrt((40.7179666 - 40.689167)^2 + (-73.9670125 - -74.044444)^2) = 0.082613886
, , . , 4 , 1,6 .
. , . , (, 48.858360, 2.294460):
sqrt((48.858360 - 40.689167)^2 + (2.294460 - -74.044444)^2) = 76.77476134
(, 41.890238, 12.492242):
sqrt((41.890238 - 40.689167)^2 + (12.492242 - -74.044444)^2) = 86.54502063
, , , 8000 , Tour Eiffel 800 .
, , - , . , . , , , ( 61.252240, -149.896769) , ( 63.049797, 179.310011). 1500 , :
sqrt((61.252240 - 63.049797)^2 + (-149.896769 - 179.310011)^2) = 329.2116875
1500 : - 50.
, , , 0 . , " ".
, , .
0 : , .
- 180 . , 180 , : http://www.bouwman.com/world/Formilab-180.html.
.
, :
distance = squareRoot(min((userLat - placeLat)^2, (userLat - placeLat - 360)^2) + (userLong - placeLong)^2)
, 360, -180 180.
, 180 , , , 180 . - : 30.84564166.
, , . "" : https://en.wikipedia.org/wiki/Geographical_distance: D