3

如何在 PHP 中计算两个纬度/经度坐标之间的每个纬度/经度坐标?

假设我有坐标A:

(39.126331, -84.113288) 

和坐标 B:

(39.526331, -84.213288)

我将如何计算这两个纬度/经度坐标(直线)之间的所有可能坐标,最多五位小数(例如 39.12633、-84.11328)并获取两者之间的坐标列表?

此外,我还有另一组坐标(坐标 C),它们稍微偏离并且不在 A 和 B 之间的坐标轨道上。

如何计算坐标 C 与 A 和 B 之间最近坐标之间的距离?

4

2 回答 2

0

这是为我解决这个问题的方法,

function point_to_line_segment_distance($startX,$startY, $endX,$endY, $pointX,$pointY)
{

        $r_numerator = ($pointX - $startX) * ($endX - $startX) + ($pointY - $startY) * ($endY - $startY);
        $r_denominator = ($endX - $startX) * ($endX - $startX) + ($endY - $startY) * ($endY - $startY);
        $r = $r_numerator / $r_denominator;

        $px = $startX + $r * ($endX - $startX);
        $py = $startY + $r * ($endY - $startY);

        $closest_point_on_segment_X = $px;
        $closest_point_on_segment_Y = $py;

        $distance = user_bomb_distance_calc($closest_point_on_segment_X, $closest_point_on_segment_Y, $pointX, $pointY);

        return array($distance, $closest_point_on_segment_X, $closest_point_on_segment_Y);
}

function user_bomb_distance_calc($uLat , $uLong , $bLat , $bLong)
{
    $earthRadius = 6371; #km
    $dLat = deg2rad((double)$bLat - (double) $uLat);
    $dlong = deg2rad((double)$bLong - (double) $uLong);

    $a = sin($dLat / 2 ) * sin($dLat / 2 ) + cos(deg2rad((double)$uLat)) * cos(deg2rad((double)$bLat)) * sin($dlong / 2) * sin($dlong / 2);


    $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
    $distance = $earthRadius * $c;

    $meter = 1000; //convert to meter 1KM = 1000M

    return  intval( $distance * $meter ) ;
}
于 2013-10-04T14:48:23.940 回答
0

您可以从所有 lat lon 对计算 voronoi 图,然后查找相邻单元格。另请注意,纬度是角度,而不是世界坐标或笛卡尔坐标。你可以在@phpclasses.org 下载我的PHP 类voronoi 图。

于 2013-09-28T17:50:39.613 回答