请记住,我将在lat / long对上执行计算,什么数据类型最适合与MySQL数据库一起使用?
当前回答
从一个完全不同和简单的角度来看:
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.
这样,您就不必担心索引号和与数据类型相关的所有其他问题,这些问题可能会破坏您的坐标。
其他回答
在GIS中使用MySQL的空间扩展。
FLOAT应该能给你所需的所有精度,并且比将每个坐标存储为字符串或类似的东西更好地用于比较函数。
如果你的MySQL版本低于5.0.3,你可能需要注意某些浮点比较错误。
在MySQL 5.0.3之前,DECIMAL列以精确的精度存储值,因为它们是用字符串表示的,但DECIMAL值的计算是使用浮点操作完成的。从5.0.3开始,MySQL执行DECIMAL操作的精度为64位十进制数字,这应该可以解决DECIMAL列最常见的不准确问题
从一个完全不同和简单的角度来看:
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.
这样,您就不必担心索引号和与数据类型相关的所有其他问题,这些问题可能会破坏您的坐标。
使用DECIMAL(8,6)表示纬度(90到-90度),使用DECIMAL(9,6)表示经度(180到-180度)。小数点后6位对于大多数应用程序都是可以的。两者都应该“有符号”以允许为负值。
不需要走太远,根据谷歌地图,最好是FLOAT(10,6)的纬度和液化天然气。