php ヒュベニの公式で距离算出

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php ヒュベニの公式で距离算出相关的知识,希望对你有一定的参考价值。

<?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)

以上是关于php ヒュベニの公式で距离算出的主要内容,如果未能解决你的问题,请参考以下文章

GPS已知首尾坐标 如何求距离

计算两个经纬度之间的距离

MySQL 大圆距离(Haversine 公式)

两地的地理坐标怎样求它们之间的距离

Python语言程序设计(六)

如何用身份证号码算出年龄???