【问题标题】:Determining course from coordinate to coordinate [duplicate]确定从坐标到坐标的过程[重复]
【发布时间】:2013-03-01 01:14:26
【问题描述】:

我有两个点(latitude1,longitude1)和(latitude2,longitude2)。如何在 PHP 中确定从第 1 点到第 2 点需要学习的课程?

课程将是北、南、东或西,可能会从度数转换?

谢谢!

【问题讨论】:

  • 我查看了右上方的链接,但结果是弧度,我真的需要度数

标签: php gps heading


【解决方案1】:
// Function: latlon_bearing_great_circle
// Desc:  This function calculates the initial bearing you need to travel
//   from Point A to Point B, along a great arc.  Repeated calls to this
//   could calculate the bearing at each step of the way.
function latlon_bearing_great_circle($lat_a, $lon_a, $lat_b, $lon_b) {
// Convert our degrees to radians:
list($lat1, $lon1, $lat2, $lon2) =
    _deg2rad_multi($lat_a, $lon_a, $lat_b, $lon_b);

// Run the formula and store the answer (in radians)
$rads = atan2(
        sin($lon2 - $lon1) * cos($lat2),
        (cos($lat1) * sin($lat2)) -
              (sin($lat1) * cos($lat2) * cos($lon2 - $lon1)) );

// Convert this back to degrees to use with a compass
$degrees = rad2deg($rads);

// If negative subtract it from 360 to get the bearing we are used to.
$degrees = ($degrees < 0) ? 360 + $degrees : $degrees;

return $degrees;
}

// Function: _deg2rad_multi
// Desc: A quick helper function.  Many of these functions have to convert
//   a value from degrees to radians in order to perform math on them.
function _deg2rad_multi() {
    // Grab all the arguments as an array & apply deg2rad to each element
    $arguments = func_get_args();
    return array_map('deg2rad', $arguments);
}

http://fil.ya1.ru/PHP_5_in_Practice/index.htm#page=0768667437/ch02lev1sec6.html

【讨论】:

  • 谢谢,我会试试看
猜你喜欢
  • 1970-01-01
  • 2011-01-14
  • 2013-12-18
  • 2011-02-18
  • 2013-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多