php 计算两个坐标(经度,纬度)之间距离的功能代码

2021-01-1708:49:02后端程序开发Comments1,646 views字数 427阅读模式

php计算两个坐标(经度,纬度)之间的距离文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20862.html

/**
 * 计算两个坐标(经度,纬度)之间的距离
 *
 * @param 
 * @arrange (512.笔记) jb51.cc
 **/
function distance($lat1,$lng1,$lat2,$lng2,$miles = true)
{
 $pi80 = M_PI / 180;
 $lat1 *= $pi80;
 $lng1 *= $pi80;
 $lat2 *= $pi80;
 $lng2 *= $pi80;
 
 $r = 6372.797; // mean radius of Earth in km
 $dlat = $lat2 - $lat1;
 $dlng = $lng2 - $lng1;
 $a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2);
 $c = 2 * atan2(sqrt($a),sqrt(1 - $a));
 $km = $r * $c;
 
 return ($miles ? ($km * 0.621371192) : $km);
}
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/20862.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/bc/20862.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定