检测坐标是否属于经度和纬度边界框

时间:2013-09-16 16:01:37

标签: math coordinates

数学从来都不是我的强项,我正在努力完成任务。

我需要确定一组经度和纬度坐标是否落在一个框内,其中已经给出了最大/最小经度和最大/最小纬度。

任何帮助都将不胜感激。

**已编辑**

我正在使用GPS坐标,因此最小经度可能大于最大经度。即如果盒子是过日期线。

3 个答案:

答案 0 :(得分:1)

if( latitude>= given.minimumLatitude and lat <= given.maximumLatitude )
{
    if( longitude >= given.minimumLongitude and longitude <= given.maximumLongitude )
    {
       return true;
    }
}

return false;

答案 1 :(得分:0)

box = left, right, top, bottom

point = x, y

if (x >= left && x <= right && y >= bottom && y <= top) {
  return true
} else {
  return false
}

答案 2 :(得分:0)

鉴于minlatmaxlatminlongmaxlong(即您框中的4个角),确定您的lat是否很简单位于minlatmaxlat之间,long位于minlongmaxlong之间。

如果横跨180°的方框要么通过添加(或减去)相同的偏移(照顾标志)来移动所有经度,要么沿着经度180°将盒子分成两个并分别测试两半

相关问题