[ php ] 위도 경도로 직선거리 계산하기 > php

본문 바로가기
사이트 내 전체검색

php

[ php ] 위도 경도로 직선거리 계산하기

페이지 정보

작성자 웹지기 댓글 0건 조회 8,434회 작성일 19-10-03 15:33

본문

첫번째 위도 경도, 두번째 위도 경도 를 통해서 직선거리 구하기

함수를 만들고 그에 해당하는 위도와 경로를 설정해서 거기를 환산해보면 된다.

값은 거리상의 km이다 소수점 아래 몇짜리까지 사용할 것인지는 알아서 판단하면 된다.

 <?php

/**

* Calculates the great-circle distance between two points, with

* the Haversine formula.

* @param float $latitudeFrom Latitude of start point in [deg decimal]

* @param float $longitudeFrom Longitude of start point in [deg decimal]

* @param float $latitudeTo Latitude of target point in [deg decimal]

* @param float $longitudeTo Longitude of target point in [deg decimal]

* @param float $earthRadius Mean earth radius in [m]

* @return float Distance between points in [m] (same as earthRadius)

**/

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;

}

 

$center_lat = 41.8350;

$center_lng = 12.470;

$lat = 41.9133741000;

$lng = 12.5203944000;

 

// test with your arccosine formula

$distance =( 6371 * acos((cos(deg2rad($center_lat)) ) * (cos(deg2rad($lat))) * (cos(deg2rad($lng) - deg2rad($center_lng)) )+ ((sin(deg2rad($center_lat))) * (sin(deg2rad($lat))))) );

print($distance); // prints 9.662174538188


// test with my haversine formula

$distance = haversineGreatCircleDistance($center_lat, $center_lng, $lat, $lng, 6371);

print($distance); // prints 9.6621745381693

?>

 

 

추천0 비추천0

댓글목록

등록된 댓글이 없습니다.

Total 82건 6 페이지
  • 열람중 [ php ] 위도 경도로 직선거리 계산하기
  • 첫번째 위도 경도, 두번째 위도 경도 를 통해서 직선거리 구하기 함수를 만들고 그에 해당하는 위도와 경로를 설정해서 거기를 환산해보면 된다. 값은 거리상의 km이다 소수점 아래 몇짜리까지 사용할 것인지는 알아서 판단하면 된다. &lt;?php /** * Calculates the great-circle distance between two points, with * the Haversine formula. * @param float $latitu...
  • 웹지기 10-03 8435 0 0 댓글 0
  • 6 [ php ] htmlspecialchars 와 json 의 관계
  • htmlspecialchars는 특수문자를 HTML 엔티티로 변환해준다. 수행되는 번역 Character Replacement &amp;(ampersand) &amp;amp; "(double quote) &amp;quot;, unles...
  • 웹지기 12-04 7899 1 0 댓글 1
  • 5 [ php ] php error root write ( php 오류 root에 저장하기 )
  • php 오류를 root페이지에 저장하고 싶을 때 /home/test/public_html 위 폴더가 root라고 할 때 해당폴더에 저장할 파일명을 아래처럼 적어준다. &lt;?php ini_set("log_errors", 1); ini_set("error_log", "/home/test/public_html/php-error.log"); ?&gt; 간단하게 ...
  • 웹지기 02-21 6915 0 0 댓글 2
  • 4 [ php ] php에서 0값의 인식문제
  • $a = 0; if(isset($a) &amp;&amp; $a!="") echo "0있어"; else echo "0없어"; 현재는 이러한 형태로 해놓은 상태이다.
  • 웹지기 03-21 6945 0 0 댓글 0
  • 3 [ php ] phpsocket.io 사용법
  • Start php start.php start for debug mode php start.php start -dfor daemon mode php start.php restart Stop php start.php stop Status php start.php status
  • 웹지기 05-08 16296 0 0 댓글 0
  • 2 [ php ] php 7.2 count() 사용시 에러 조치
  • Severity: Warning --&gt; count(): Parameter must be an array or an object that implements Countable 기존에는 빈값일 때 문제 없었는데, 7.2버젼에서는 빈값이면 0이 아니기 때문에 오류가 발생했다. if(count($num) &gt; 0) { echo "test"; } 이부분에서 문제가 생겨서 다음처럼 수정을 했다. i...
  • 웹지기 06-08 8995 0 0 댓글 0
  • 1 [ php ] foreach() 오류 Invalid argument supplied for foreach()
  • Invalid argument supplied for foreach() 이러한 오류가 발생하는것은 foreach에 검색하는 변수의 값이 비어있기 때문. 어쩔수 없이 빈값인지 확인해야 한다. if(!emepty($변수)) { foreach($변수 AS $key) { echo "샬랄라"; } } 이런식으로 감싸줘야 ㅡㅡ;;
  • 웹지기 06-08 9602 0 0 댓글 0
게시물 검색

회원로그인

접속자집계

오늘
3,615
어제
8,307
최대
33,828
전체
8,655,081

그누보드5
Copyright © funyphp.com. All rights reserved.