Detect if a co-ordinate falls within a longitude and latitude boundary box

ぃ、小莉子 提交于 2019-12-04 22:45:17

Given minlat, maxlat, minlong and maxlong (ie the 4 corners of your box) then it's a simple matter of determining whether your lat lies between minlat and maxlat and your long between minlong and maxlong.

If the box straddles 180° either shift all your longitudes by adding (or subtracting) the same offset (take care with signs) or split the box into two along longitude 180° and test both halves separately.

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

return false;
box = left, right, top, bottom

point = x, y

if (x >= left && x <= right && y >= bottom && y <= top) {
  return true
} else {
  return false
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!