您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP下的经纬度求距离

2024/3/11 1:38:52发布55次查看
/*** @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); }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product