Created
August 7, 2013 14:10
-
-
Save HituziANDO/6174405 to your computer and use it in GitHub Desktop.
2地点間距離の二乗を計算します
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* input: 2点の緯度経度(10進数) | |
* output: 2点間距離の2乗(km^2) | |
*/ | |
function geo_distance2 ($lat1, $lng1, $lat2, $lng2) { | |
$earth_r = 6378.137; // 地球の半径(km) | |
$deltaLat = deg2rad($lat2 - $lat1); // 緯度差(角度ラジアン) | |
$deltaLng = deg2rad($lng2 - $lng1); // 経度差(角度ラジアン) | |
$distanceNS = $earth_r * $deltaLat; // 南北の距離 | |
$distanceEW = cos(deg2rad($lat1)) * $earth_r * $deltaLng; // 東西の距離 | |
$distance_km2 = pow($distanceNS, 2) + pow($distanceEW, 2); | |
return $distance_km2; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment