mugyu
12/14/2017 - 5:57 PM

ヒュベニの公式で距離算出

二点の緯度経度の距離を算出します

<?php

function get_distance($send_lat, $send_log, $spot_lat, $spot_log) {
	// 地球の赤道半径(m)
	static $equator_radius = 6378137;

  // ヒュベニの公式
  // https://en.wikipedia.org/wiki/Haversine_formula
	return $equator_radius * acos(
		cos(deg2rad($send_lat)) * cos(deg2rad($spot_lat)) * cos(deg2rad($spot_log) - deg2rad($send_log)) + 
		sin(deg2rad($send_lat)) * sin(deg2rad($spot_lat)) 
	);
}

$distance = get_distance(34.789296, 135.437928, 34.789276804608, 135.43790817261);
var_dump($distance); # => double(2.8033258550543)