我有一个圆生成器,它可以围绕lat和lon绘制一个KML圆.它对我输入的99%的坐标都能正常工作,但是如果位置靠近国际日期线,它会在绘图中阻塞. 我想知道是否有人处理过这个问题,并提供了一个解决方案.

这是我的循环,如果我使用坐标,我使用的是19.282494,166.636650 我的半径是1047 NM,因为它绕着它穿过国际日期的点迭代 排队.这是它的输出,当它经过0度和180度时,它似乎窒息了

<coordinates>166.63665,36.70122262,30 170.33929602,36.39506383,30 173.86075879,35.49288317,30 177.04308391,34.04103068,30 179.76710126,32.10928643,30 -178.04299159,29.78247231,30 -176.42417943,27.15263215,30 -175.38386586,24.31316399,30 -174.90965799,21.35519771,30 -174.97725208,18.36580524,30 -175.55559428,15.42737555,30 -176.60947581,12.617518,30 -178.10014056,10.00900144,30 -179.98458741,7.66939861,30 177.7857603,5.66025581,30 175.26638245,4.0357509,30 172.52041272,2.84094525,30 169.61836825,2.10986796,30 166.63665,1.86376538,30 163.65493175,2.10986796,30 160.75288728,2.84094525,30 158.00691755,4.0357509,30 155.4875397,5.66025581,30 153.25788741,7.66939861,30 151.37344056,10.00900144,30 149.88277581,12.617518,30 148.82889428,15.42737555,30 148.25055208,18.36580524,30 148.18295799,21.35519771,30 148.65716586,24.31316399,30 149.69747943,27.15263215,30 151.31629159,29.78247231,30 153.50619874,32.10928643,30 156.23021609,34.04103068,30 159.41254121,35.49288317,30 162.93400398,36.39506383,30 166.63665,36.70122262,30 </coordinates>
foreach($ap as $name)
{
    $name=trim(strtoupper($name));
    $circleLat = $airport[$name][0];
    $circleLon = $airport[$name][1];
    $circleRadius = $_GET['circleRadius']*1852;
    $circlePrecision = mostPrecision($circleLat, $circleLon, $circleRadius);
    $coordinatesList = "";
    // Code based on Google Earth community posting by 'ink_polaroid'
    // http://bbs.keyhole.com/ubb/showflat.php/Cat/0/Number/23634/an//page//vc/1
    $num_points = 36;
    $delta_pts = 360/$num_points;
    // convert coordinates to radians
    $lat = deg2rad(floatval($circleLat));
    $lon = deg2rad(floatval($circleLon));
    $d = $circleRadius;
    $d_rad = $d/6378137; // convert dist to angular distance in radians
    // loop around the compass, appending coordinates of each vertex
    for($i=0; $i<=$num_points; $i++) {  
      $radial = deg2rad($i*$delta_pts);
      $lat_rad = asin(sin($lat)*cos($d_rad) + cos($lat)*sin($d_rad)*cos($radial));
      $dlon_rad = atan2(sin($radial)*sin($d_rad)*cos($lat), cos($d_rad)-sin($lat)*sin($lat_rad));
      $lon_rad = fmod(($lon+$dlon_rad + M_PI), 2*M_PI) - M_PI;
      $coordinatesList .= Round(rad2deg($lon_rad),$circlePrecision).",".Round(rad2deg($lat_rad),$circlePrecision).",30 ";
    }

提亚 史蒂夫

推荐答案

我已经大大简化了您的代码,只需绕过机场的坐标即可.

foreach($ap as $name)
{
    $name=trim(strtoupper($name));
    $circleLat = $airport[$name][0];
    $circleLon = $airport[$name][1];
    $circleRadius = $_GET['circleRadius']*1852;
    $circlePrecision = mostPrecision($circleLat, $circleLon, $circleRadius);
    $coordinatesList = "";
    // Code based on Google Earth community posting by 'ink_polaroid'
    // http://bbs.keyhole.com/ubb/showflat.php/Cat/0/Number/23634/an//page//vc/1
    $num_points = 36;
    $delta_pts = 360/$num_points;
    // convert coordinates to radians
    $lat = deg2rad(floatval($circleLat));
    $lon = deg2rad(floatval($circleLon));
    $d = $circleRadius;
    $d_rad = $d/6378137; // convert dist to angular distance in radians
    // loop around the compass, appending coordinates of each vertex
    for($i=0; $i<=$num_points; $i++) {  
      $radial = deg2rad($i*$delta_pts);
      $lonCircle = $d_rad*sin($radial);
      $latCircle = $d_rad*cos($radial);
      $coordinatesList .= Round(rad2deg($lon+$lonCircle),$circlePrecision).",".
                          Round(rad2deg($lat+$latCircle),$circlePrecision).",30 ";
    }
}

这将返回:

166.63665,36.70122,30
169.66138,36.43659,30
172.59421,35.65074,30
175.34601,34.36756,30
177.83319,32.62601,30
179.98017,30.47904,30
181.72171,27.99186,30
183.0049,25.24005,30
183.79075,22.30722,30
184.05538,19.28249,30
183.79075,16.25776,30
183.0049,13.32494,30
181.72171,10.57313,30
179.98017,8.08595,30
177.83319,5.93897,30
175.34601,4.19743,30
172.59421,2.91424,30
169.66138,2.1284,30
166.63665,1.86377,30
163.61192,2.1284,30
160.67909,2.91424,30
157.92729,4.19743,30
155.44011,5.93897,30
153.29313,8.08595,30
151.55159,10.57313,30
150.2684,13.32494,30
149.48255,16.25776,30
149.21792,19.28249,30
149.48255,22.30722,30
150.2684,25.24005,30
151.55159,27.99186,30
153.29313,30.47904,30
155.44011,32.62601,30
157.92729,34.36756,30
160.67909,35.65074,30
163.61192,36.43659,30
166.63665,36.70122,30

当然,为了清楚起见,没有回报,回报只存在于结果中.请参见this fiddle.

我不知道这是否真的适用于您的Keyhole标记语言应用程序,这是您需要try 的东西.

Php相关问答推荐

SQLSTATE [42S02]:找不到基表或视图:1146 Table eshop. sessions不存在'''

致命错误:无法使用简单的php博客重新声明spl_autoload_Register()

PHP中冒号的奇怪用例

Laravel;Composer安装突然返回选项快捷方式不能为空.

基于不用于变体的产品属性隐藏多个WooCommerce发货方式

PHP空数组定义与开始或结束逗号

将客户重定向到自定义感谢页后的空白页

防止同时从Laravel中的用户帐户中提取

允许在WooCommerce管理订单列表中使用计费邮箱进行搜索

如何用十进制和字母数字减go 和添加 id

多个产品类别 Select 自定义 WooCommerce 插件设置页面

添加产品标签以通过 WooCommerce 邮箱通知订购商品

在特征中使用类的属性

计算数组中连续值的数量

为WooCommerce中的运输方式ID设置必填的 checkout 订单备注字段

WooCommerce单个产品页面上启用额外选项卡的产品元框字段

如何在 WooCommerce 中显示每个自定义选项卡的内容

如果 static:: 被解析为B,为什么 PHP 会执行A的方法

服务器发送的事件:EventSource 抛出 MIME 错误

在 foreach 循环中重命名 PHP 对象属性