给定初始纬度 lng,距离和方位角,在 php 中查找纬度经度点
Posted
技术标签:
【中文标题】给定初始纬度 lng,距离和方位角,在 php 中查找纬度经度点【英文标题】:FInd latitude longitude point in php given initial lat lng, distance, and bearing 【发布时间】:2012-06-22 02:08:21 【问题描述】:在 php 中,给定一个纬度和经度点、方位角(以度为单位)和距离(以英尺或公里或其他为单位)我如何确定新的 lat lng 点是什么?这是我尝试过的,但它是错误的。
function destinationPoint($lat, $lng, $brng, $dist)
$meters = $dist/3.2808399; // dist in meters
$dist = $meters/1000; // dist in km
$rad = 6371; // earths mean radius
$dist = $dist/$rad; // convert dist to angular distance in radians
$brng = deg2rad($brng); // conver to radians
$lat1 = deg2rad($lat);
$lon1 = deg2rad($lng);
$lat2 = asin(sin($lat1)*cos($dist) + cos($lat1)*sin($dist)*cos($brng) );
$lon2 = $lon1 + atan2(sin($brng)*sin($dist)*cos($lat1),cos($dist)-sin($lat1)*sin($lat2));
$lon2 = ($lon2+3*M_PI) % (2*M_PI) - M_PI; // normalise to -180..+180º
$lat2 = rad2deg($lat2);
$lon2 = rad2deg($lon2);
echo "lat2 = ".$lat2."<br/>";
echo "lon2 = ".$lon2."<br/>";
【问题讨论】:
【参考方案1】:只是改变
$lon2 = ($lon2+3*M_PI) % (2*M_PI) - M_PI;
到
$lon2 = fmod($lon2 + 3*M_PI, 2*M_PI) - M_PI;
根据PHP's documentation about the modulus operator (%
),
模数的操作数在处理之前被转换为整数(通过去除小数部分)。
fmod "[r] 返回参数除法的浮点余数(模)。"
【讨论】:
以上是关于给定初始纬度 lng,距离和方位角,在 php 中查找纬度经度点的主要内容,如果未能解决你的问题,请参考以下文章