php - 在给定初始经纬度、距离和方位角的情况下,在 php 中查找经纬度点

标签 php google-maps distance bearing

在 php 中,给定一个纬度和经度点、一个方位角(以度为单位)和一个距离(以英尺或公里或其他单位为单位)我如何计算出新的经纬度点是什么?这是我尝试过的方法,但这是错误的。

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/>";
    }

最佳答案

改变

$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 (%) ,

Operands of modulus are converted to integers (by stripping the decimal part) before processing.

fmod “[r] 返回参数除法的浮点余数(模)。”

关于php - 在给定初始经纬度、距离和方位角的情况下,在 php 中查找经纬度点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11111077/

相关文章:

php - 如何将 javascript 变量传递给下拉列表中的选项值?

cluster-analysis - 混合变量(分类和数字)距离函数

php - 如何将数字格式化为货币但不显示符号?

php - 如何使用 Symfony 中的 FosUserBundle 访问用户管理器作为服务?

php - 显示没有链接的 WordPress 类别列表

javascript - 如何从Google的Api坐标JS获取地址

java - PreferenceCategory 主题不适用于 PreferenceScreen

algorithm - 找到离其他 n 个点最远的点

rotation - 两个四元数之间的 "Distance"(或角幅度)?

php - 无法在 PHP、MySql 中上传 3mb+ 文件