Home > php教程 > php手册 > body text

php计算两个坐标(经度,纬度)之间距离的方法,坐标经度

WBOY
Release: 2016-06-13 09:06:44
Original
1165 people have browsed it

php计算两个坐标(经度,纬度)之间距离的方法,坐标经度

本文实例讲述了php计算两个坐标(经度,纬度)之间距离的方法。分享给大家供大家参考。具体如下:

这里使用php计算两个坐标(经度,纬度)之间的距离,返回结果为米或者千米

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);
}
Copy after login

希望本文所述对大家的php程序设计有所帮助。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!