LoginSignup
9
8

More than 5 years have passed since last update.

緯度経度で距離計算(php)

Posted at

//緯度、経度の移動量を計算
$lat_dist = ($start_lat - $end_lat);if($lat_dist<0)$lat_dist=$lat_dist*-1;
$lng_dist = ($start_lng - $end_lng);if($lng_dist<0)$lng_dist=$lng_dist*-1;


//緯度位置における経度量を計算 地球は丸い
$m_lng = 30.9221438 * cos($start_lat / 180 * pi());
if($m_lng<0)$m_lng=$m_lng*-1;

//移動量を計算
$distance = (int)(sqrt(pow(abs($lat_dist / 0.00027778 * 30.9221438), 2) + pow(abs($lng_dist / 0.00027778 * $m_lng), 2)));

基本、緯度や赤道での経度の場合0.00027778度で30.9221438mになるので
移動量を0.00027778で割って30.9221438を掛けた値で三角関数を使う。
ただし、緯度は変化しないが緯度によって経度ごとの距離は変わるので
ひとまずスタート地点の緯度でその緯度で経度移動量を計算しておく

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8