dtf76989 2015-06-14 08:55
浏览 108
已采纳

确定坐标是否在区域内(MKMapView,用PHP解决)

I'm using MKMapView and I send my php program the visible region (center lat, center lon, span lat, span lon). I need to determine if a coordinate is inside that region using php. I'm hoping there's a standard formula somewhere, but I haven't found one. I'll keep trying to come up with a formula, but it's surprisingly complicated (hopefully not as much as the haversine, which I don't believe I could have figured out myself).

  • 写回答

4条回答 默认 最新

  • dongyunqin7307 2015-06-24 03:47
    关注

    My Solution

    $top = $c_lat + ($d_lat / 2.0);
    $bottom = $c_lat - ($d_lat / 2.0);
    $left = $c_lon - ($d_lon / 2.0);
    $right = $c_lon + ($d_lon / 2.0);
    if($left < -180)
    {
        $second_left = $left + 360.0;
        $second_right = 180.0;
        $left = -180;
    }
    elseif($right > 180)
    {
        $second_right = $right - 360.0;
        $second_left = -180.0;
        $right = 180.0;
    }
    $inside = false;
    if($t_lat > $bottom && $t_lat < $top && $t_lon > $left && $t_lon < $right)
        $inside = true;
    else if($second_right && $second_left)
    {
        if($t_lat > $bottom && $t_lat < $top && $t_lon > $second_left && $t_lon < $second_right)
            $inside = true;
    }
    
    if($inside)
    {
    
    }
    

    This seems to work with MKMapView since the region latitudes are always between -90 and 90.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退