简体   繁体   English

从纬度/经度和“半径”创建边界框

[英]Creating a bounding box from a latitude/longitude and a 'radius'

I have been looking for a piece of code (preferably in PHP) which can take a latitude, longitude and a plus/minus value (in Km) and return the minimum and maximum latitude and longitudes. 我一直在寻找一段代码(最好在PHP中),该代码可以采用纬度,经度和正负值(以Km为单位),并返回最小和最大纬度和经度。

I can't seem to find anything which both explains what it does in simplistic terms as well as takes into account the 'bloated' curvature of the earth. 我似乎找不到任何能以简单的方式解释它的功能以及考虑到地球“膨胀”的曲率的东西。

Can anyone help? 有人可以帮忙吗?

This is tricky because latitude/longitude is an angular quantity, whereas your radius distance is an incompatible linear quantity. 这很棘手,因为纬度/经度是一个角度量,而半径距离是一个不兼容的线性量。

Here are some methods of solving it, in decreasing order of accuracy and increasing order of simplicity of coding. 这里有一些解决方法,以降低准确度的顺序和增加编码简单性的顺序。

  1. Use a projection library to first do the calculations in projected coordinates (x,y) and then re-project back to (lat,lon). 使用投影库首先在投影坐标(x,y)中进行计算,然后重新投影回(lat,lon)。 There is a php port of the well-respected proj4 library , and I see PEAR has a projection library too. 有一个备受推崇的proj4库的php端口,我看到PEAR也有一个投影库。
  2. Approximate the Earth by an ellipsoid with WGS84 parameters. 用具有WGS84参数的椭球近似地球。 See the accepted answer of this question . 请参阅此问题的公认答案。
  3. Approximate the Earth by a sphere and use spherical trigonometry. 用球体近似地球,并使用球三角函数。 See the accepted answer of this question . 请参阅此问题的公认答案。
  4. Use simple proportion of approximate conversion factors for your area of interest. 对您感兴趣的区域使用简单比例的近似转换因子。 See the accepted answer of this question . 请参阅此问题的公认答案。

I recommend no. 我不建议。 1. 1。

Not sure why why you want to do this in pure PHP but MySQL and MongoDB support geospatial indexing which has huge performance advantage over any pure PHP implementation. 不知道为什么要在纯PHP中执行此操作,但是MySQLMongoDB支持地理空间索引,这比任何纯PHP实现都具有巨大的性能优势。

I personal prefer the MongoDB version because it installed by default and you can easily serach by 我个人更喜欢MongoDB版本,因为它是默认安装的,您可以轻松地通过

  • Near
  • Radius 半径
  • Box
  • Polygon 多边形
  • Distance 距离

Please See 请参见

为了使事情变得更容易,我切换到了MongoDB的系统,并且目前正在使用MongoHQ的REST API来通过其geo API访问数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM