gpt4 book ai didi

php - 从两个经纬度和方向之间得到经纬度

转载 作者:行者123 更新时间:2023-12-03 23:00:16 26 4
gpt4 key购买 nike

我正在开发一个应用程序,我需要在两个经度之间的经度。

所以我所拥有的是

1) 起点经纬度

2) 终点经纬度

3)方向,如南(180度)或北(0度)

4) 两点之间的距离

现在我要做的是将整个路径分成一些 block ,就像我将将整个路径除以 10 公里

So lets say total distance is 100KM then I will get 10 chunks.

if 200KM then there will be 20 chunks.

所以现在我想从两个纬度中找出那些点的纬度。

所以所有 20 个点应该在一条线上并且距离相等。

如何实现?

最佳答案

您可以尝试取两个 Lat Lon 点之间的差值,将它们除以 block 数。这将给出“增量”。然后可以根据方向在循环中添加或移除,以在两者之间创建点。

考虑以下我做的测试:

//Position 1
$lat1 = 53.2226754;
$lon1 = 0.124584;

//Position 2
$lat2 = 52.212445;
$lon2 = -0.12458;

//Differences in Lat / Lon
$latDif = round($lat1 - $lat2, 7);
$lonDif = round($lon1 - $lon2, 7);

//Calculate Step / Increment
//I used 10 as an example for the number of steps
$chunks = 10;
$latStep = round($latDif / $chunks, 7);
$lonStep = round($lonDif / $chunks, 7);

//New Lat Lon starts at start point
$newLat = $lat1;
$newLon = $lon1;


echo $lat1 . ", " . $lon1 . "<br>"; //Start Point

for($i = 1; $i < $chunks; $i++){

//Direction could be substituted here

if($lat1 < $lat2){
$newLat = $newLat + $latStep; //Going North
} else {
$newLat = $newLat - $latStep; //Going South
}

if($lon1 < $lon2){
$newLon = $newLon + $lonStep; //Going East
} else {
$newLon = $newLon - $lonStep; //Going West
}

echo $newLat . ", " . $newLon . "<br>"; //New Point
}

echo $lat2 . ", " . $lon2 . "<br>"; //End Point

这导致以下 Lat Lon 输出:

53.2226754, 0.124584;
53.1216524, 0.0996676;
53.0206294, 0.0747512;
52.9196064, 0.0498348;
52.8185834, 0.0249184;
52.7175604, 0.0000002;
52.6165374, -0.0249144;
52.5155144, -0.0498308;
52.4144914, -0.0747472;
52.3134684, -0.0996636;
52.212445, -0.12458;

我将这些绘制在 online geoplanner 上并得到以下内容:

Geoplanner output of Lat Lon

GPS Results Link

关于php - 从两个经纬度和方向之间得到经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36451820/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com