[PHP] 위도, 경도 값을 활용하여 거리순으로 출력하기
오늘은 PHP , MySQL 쿼리문을 Haversine 공식으로 활용하여 GET 요청에서 위도와 경도 값을 가져와 이를 기반으로 거리를 계산하고. 그런 다음 5 킬로미터 이내의 위치에 저장된 데이터를 데이터베이스에서 가져와 표시하는 예제를 만들어 보겠습니다.
Haversine 공식이란?
Haversine 공식은 경도 와 위도 고려하여 구 위의 두 점 사이의 대원 거리를 결정하는 공식입니다.
https://en.wikipedia.org/wiki/Haversine_formula
Haversine formula - Wikipedia
From Wikipedia, the free encyclopedia Formula for the great-circle distance between two points on a sphere The haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes. Important in navigati
en.wikipedia.org
우선 제가 저장했던 MySQL DB에 저장된 데이터 입니다.
다음으로 PHP 코드입니다.
해당 파일에 GET요청을 URI 뒤에 이런식으로 적어보세요
yourAddr/phpFileName.php?latitude=127.0396007&longitude=37.5482659
latitude=127.0396007&longitude=37.5482659 해당 좌표는 수성구쪽 좌표입니다.
해당 좌표로 요청한 5키로미터 이내의 사람들을 출력한 결과입니다.