计算两个Lat/Long坐标之间的所有坐标,精确到小数点后x位


Calculate all coordinates to x decimal places between two Lat/Long coordinates

如何在PHP中计算两个Lat/Long坐标之间的每个Lat/Long座标?

假设我有坐标A:

(39.126331, -84.113288) 

坐标B:

(39.526331, -84.213288)

我如何计算这两个Lat/Long坐标(直线)之间的每一个可能的坐标,最多小数点后五位(例如39.12633,-84-11328),并获得这两个坐标之间的坐标列表?

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

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

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

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 ) ;
}