/*** @desc 根据两点间的经纬度计算距离* @param float $lat 纬度值* @param float $lng 经度值*/ function getdistance($lat1, $lng1, $lat2, $lng2) { $earthradius = 6367000; //approximate radius of earth in meters /* convert these degrees to radians to work with the formula */ $lat1 = ($lat1 * pi() ) / 180; $lng1 = ($lng1 * pi() ) / 180; $lat2 = ($lat2 * pi() ) / 180; $lng2 = ($lng2 * pi() ) / 180; /* using the haversine formula http://en.wikipedia.org/wiki/haversine_formula calculate the distance */ $calclongitude = $lng2 - $lng1; $calclatitude = $lat2 - $lat1; $stepone = pow(sin($calclatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calclongitude / 2), 2); $steptwo = 2 * asin(min(1, sqrt($stepone))); $calculateddistance = $earthradius * $steptwo; return round($calculateddistance); }
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号