dongyi2993 2015-12-03 12:30
浏览 57
已采纳

如何确定位置是否在正方形(lat,lon)PHP内

How can you figure out if this:

$Now = array(
'lat' => '59.565423',
'long' => '7.347268'
);

is inside this:

$x = array(
'x1' => '59.570281',  // point 1, north west - lat
'y1' => '7.341667',   // ^^^^^^ - lon
'x2' => '59.570281',  // point 2, north east - lat
'y2' => '7.351087',   // ^^^^^^ - lon
'x3' => '59.568195',  // point 3, south east - lat
'y3' => '7.351087',   // ^^^^^^ - lon
'x4' => '59.568195',  // point 4, south west - lat
'y4' => '7.341667'    // ^^^^^^ - lon
 );

Supposed to return 1 if inside or 0 if outside.

  • 写回答

1条回答 默认 最新

  • douxu5233 2015-12-03 12:30
    关注

    Here is how:

    • first you need to check if longitude is within your |---| area so:

      if($Now['long'] > $x['y1'] && $Now['long'] < $x['y2'])

      • then you need to check if the latitude is within the parameters:

      if($Now['lat'] < $x['x1'] && $Now['lat'] > $x['x4'])

    Whole function:

    function InsideOrNot($Now, $x){
        //If 0 is within |----| (|--0--|)
        if($Now['long'] > $x['y1'] && $Now['long'] < $x['y2']){
    
            //if 0 is within ___
            //                |
            //               ___   
            if($Now['lat'] < $x['x1'] && $Now['lat'] > $x['x4']){
                return 1;
            }
    
            else{
                return 0;
            }
        }
        else{
            return 0;
        }
    
    
    }
    

    Now: echo InsideOrNot($Now, $x);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog