给定初始纬度,距离和方位角的php中的第一个纬度经度点 [英] FInd latitude longitude point in php given initial lat lng, distance, and bearing

查看:238
本文介绍了给定初始纬度,距离和方位角的php中的第一个纬度经度点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In php, given a latitude and longitude point, a bearing (in degrees), and a distance (in feet or km or whatever) how do I figure out what the new lat lng point is? here is what I tried, but it's wrong.

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文档

According to PHP's documentation about the modulus operator (%),

模数的运算在处理之前会转换为整数(通过去除小数部分).

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

fmod "[r]返回浮点余数(模)的参数划分."

fmod "[r]eturns the floating point remainder (modulo) of the division of the arguments."

这篇关于给定初始纬度,距离和方位角的php中的第一个纬度经度点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆