请记住,我将在lat / long对上执行计算,什么数据类型最适合与MySQL数据库一起使用?


当前回答

在GIS中使用MySQL的空间扩展。

其他回答

PostGIS中的空间函数比MySQL中的空间函数更具功能性(即不局限于BBOX操作)。看看:链接文本

我们将纬度/经度X 1,000,000作为数字存储在oracle数据库中,以避免使用双数舍入错误。

已知纬度/经度精确到小数点后第6位是10厘米,这就是我们所需要的。许多其他数据库也将lat/long存储到小数点后第6位。

MySQL的空间扩展是最好的选择,因为你有空间操作符和索引的完整列表。空间索引允许您非常快速地执行基于距离的计算。请记住,作为6.0,空间扩展仍然是不完整的。我并不是在写MySQL Spatial,只是让你在深入了解它之前知道它的缺陷。

如果你严格地处理点,而只是DISTANCE函数,这是可以的。如果需要使用polygon、Lines或Buffered-Points进行任何计算,除非使用“related”操作符,否则空间操作符不会提供准确的结果。请参阅21.5.6顶部的警告。关系,如包含,内部,或交叉使用MBR,而不是确切的几何形状(即椭圆被视为矩形)。

此外,MySQL Spatial中的距离与第一个几何图形的单位相同。这意味着如果你使用的是十进制度数,那么你的距离测量就是十进制度数。当你离赤道越来越远时,这将使你很难得到准确的结果。

根据您的应用程序,我建议使用FLOAT(9,6)

空间键将为您提供更多的功能,但在生产基准测试中,浮点数比空间键快得多。(在AVG中0,01 VS 0,001)

从一个完全不同和简单的角度来看:

if you are relying on Google for showing your maps, markers, polygons, whatever, then let the calculations be done by Google! you save resources on your server and you simply store the latitude and longitude together as a single string (VARCHAR), E.g.: "-0000.0000001,-0000.000000000000001" (35 length and if a number has more than 7 decimal digits then it gets rounded); if Google returns more than 7 decimal digits per number, you can get that data stored in your string anyway, just in case you want to detect some flees or microbes in the future; you can use their distance matrix or their geometry library for calculating distances or detecting points in certain areas with calls as simple as this: google.maps.geometry.poly.containsLocation(latLng, bermudaTrianglePolygon)) there are plenty of "server-side" APIs you can use (in Python, Ruby on Rails, PHP, CodeIgniter, Laravel, Yii, Zend Framework, etc.) that use Google Maps API.

这样,您就不必担心索引号和与数据类型相关的所有其他问题,这些问题可能会破坏您的坐标。