RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
php数据库经纬度距离,php获取经纬度

php经纬度之间的距离怎么算单位是公里

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

成都创新互联公司专业为企业提供五指山网站建设、五指山做网站、五指山网站设计、五指山网站制作等企业网站建设、网页设计与制作、五指山企业网站模板建站服务,10余年五指山做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

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

}

php 怎么计算两个经纬度直接的距离

/**

* @desc 根据两点间的经纬度计算距离

* @param float $lat 纬度值

* @param float $lng 经度值

*/

function getDistance($lat1, $lng1, $lat2, $lng2) {

$earthRadius = 6367000; //approximate radius of earth in meters

$lat1 = ($lat1 * pi() ) / 180;

$lng1 = ($lng1 * pi() ) / 180;

$lat2 = ($lat2 * pi() ) / 180;

$lng2 = ($lng2 * pi() ) / 180;

$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 计算地图上两个坐标之间的距离

define('EARTH_RADIUS', 6378.137);//地球半径,假设地球是规则的球体

define('PI', 3.1415926);

/**

* 计算两组经纬度坐标 之间的距离

* params :lat1 纬度1; lng1 经度1; lat2 纬度2; lng2 经度2; len_type (1:m or 2:km);

* return m or km

*/

function GetDistance($lat1, $lng1, $lat2, $lng2, $len_type = 1, $decimal = 2)

{

$radLat1 = $lat1 * PI ()/ 180.0; //PI()圆周率

$radLat2 = $lat2 * PI() / 180.0;

$a = $radLat1 - $radLat2;

$b = ($lng1 * PI() / 180.0) - ($lng2 * PI() / 180.0);

$s = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1) * cos($radLat2) * pow(sin($b/2),2)));

$s = $s * EARTH_RADIUS;

$s = round($s * 1000);

if ($len_type -- 1)

{

$s /= 1000;

}

return round($s, $decimal);

}

echo GetDistance(39.908156,116.4767, 39.908452,116.450479, 1);//输出距离/米


本文标题:php数据库经纬度距离,php获取经纬度
本文URL:http://scyingshan.cn/article/hssjej.html