请记住,我将在lat / long对上执行计算,什么数据类型最适合与MySQL数据库一起使用?
当前回答
根据这篇维基文章 http://en.wikipedia.org/wiki/Decimal_degrees#Accuracy MySQL中适当的数据类型是Decimal(9,6),用于存储经度和纬度 单独的字段。
其他回答
基本上,这取决于你需要的定位精度。使用DOUBLE可以获得3.5nm的精度。DECIMAL(8,6)/(9,6)减小到16cm。FLOAT是1.7米…
这个非常有趣的表格有一个更完整的列表:http://mysql.rjweb.org/doc.php/latlng:
Datatype Bytes Resolution
Deg*100 (SMALLINT) 4 1570 m 1.0 mi Cities
DECIMAL(4,2)/(5,2) 5 1570 m 1.0 mi Cities
SMALLINT scaled 4 682 m 0.4 mi Cities
Deg*10000 (MEDIUMINT) 6 16 m 52 ft Houses/Businesses
DECIMAL(6,4)/(7,4) 7 16 m 52 ft Houses/Businesses
MEDIUMINT scaled 6 2.7 m 8.8 ft
FLOAT 8 1.7 m 5.6 ft
DECIMAL(8,6)/(9,6) 9 16cm 1/2 ft Friends in a mall
Deg*10000000 (INT) 8 16mm 5/8 in Marbles
DOUBLE 16 3.5nm ... Fleas on a dog
PostGIS中的空间函数比MySQL中的空间函数更具功能性(即不局限于BBOX操作)。看看:链接文本
在GIS中使用MySQL的空间扩展。
存储Lat Long值的理想数据类型是十进制(9,6)
这是在大约10cm的精度,而只使用5字节的存储。
例如:CAST(123.456789 as decimal(9,6))
从一个完全不同和简单的角度来看:
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.
这样,您就不必担心索引号和与数据类型相关的所有其他问题,这些问题可能会破坏您的坐标。
推荐文章
- 将值从同一表中的一列复制到另一列
- 删除id与其他表不匹配的sql行
- 关于数据库,每个开发人员应该知道些什么?
- MySQL CPU使用率高
- INT和VARCHAR主键之间有真正的性能差异吗?
- 拒绝访问;您需要(至少一个)SUPER特权来执行此操作
- 从存储引擎得到错误28
- "where 1=1"语句
- 是使用各有一个模式的多个数据库更好,还是使用一个数据库有多个模式更好?
- 可能做MySQL外键的两个可能的表之一?
- 如果字段在MySQL中为空,则返回0
- 对于PostgreSQL表来说,多大才算太大?
- 在MySQL中检测值是否为number
- MySQL中两个日期之间的差异
- 为什么在MySQL中文本列不能有一个默认值?