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

有些话、适合烂在心里 提交于 2019-12-12 09:27:07

问题


Maths has never been my strong point and I'm struggling with a task.

I need to determine if a set of longitude and latitude co-ordinates fall inside a box, where the max/min longitude and max/min latitude have been given.

Any help would be appreciated.

** EDITED **

I'm using GPS co-ordinates, so the minimum longitude could be larger than the maximum longitude. i.e if the box is over date line.


回答1:


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.




回答2:


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

return false;



回答3:


box = left, right, top, bottom

point = x, y

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


来源:https://stackoverflow.com/questions/18832450/detect-if-a-co-ordinate-falls-within-a-longitude-and-latitude-boundary-box

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!