php - 如何获取围绕中心坐标和半径的N个坐标

标签 php swift google-maps mapkit coordinate-transformation

我有一个中心坐标和一个距离/半径,我需要使用半径从中心获取 N 个坐标,例如如何获取下图中红点的 12 个坐标。

enter image description here

最佳答案

您可以使用 Great-circle_distance计算得到的分数。

我首先从所需的中心点计算方位角,然后 foreach 循环它们并将它们传递给函数。

function destinationPoint($lat, $lng, $brng, $dist) {
    $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 = fmod($lon2 + 3*M_PI, 2*M_PI) - M_PI;  // normalise to -180..+180º
    $lat2 = rad2deg($lat2);
    $lon2 = rad2deg($lon2);


    echo "lat = ".$lat2."\n";
    echo "lon = ".$lon2."\n\n";
}

$lat = 0;
$lng = 0;
$dist = 1; // km
$n = 12;

$bearings = range(0, 360-(360/$n)  , 360/$n); // create array of all bearings needed from $lat/$lng

foreach($bearings as $brng){
    echo $brng ."\n";
    destinationPoint($lat, $lng, $brng, $dist);
}

理论上,根据您需要的准确度,您只需要使用该函数计算出一半的值,然后您应该能够通过基本计算计算出另一半。
但如果距离很大(不知道究竟是什么意思),它可能会有所不同。

https://3v4l.org/4fI7F

关于php - 如何获取围绕中心坐标和半径的N个坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50133937/

相关文章:

php - Twig 显示额外字段

javascript - 谷歌地图覆盖不会定位在正确的标记上

php - 在 PHP Web 应用程序中构建时区功能

php - 如何通过单击按钮删除某些表格行

ios - 为什么在 Collection View 中显示奇怪的线条?

swift - API 调用似乎正在遍历并收集数据,但数据未显示在我的自定义表格 View 单元格中

ios - 在 Swift 3 中访问闭包外的数组

javascript - Angularjs ui-gmap-window 对象数据不呈现

javascript - gmap3 获取集群位置

php - 在网页上显示 PHP/SQL 查询以进行调试