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


当前回答

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

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

其他回答

纬度范围从-90到+90(度),因此DECIMAL(10,8)是可以的 经度范围从-180到+180(度),因此需要DECIMAL(11,8)。

注:第一个数字是存储的总位数,第二个数字是小数点后的数字。

简而言之:latdecimal (10,8) NOT NULL, lng DECIMAL(11,8) NOT NULL

GeoLocationCoordinates返回一个双数据类型,以十进制表示位置的经纬度。你可以试着用double。

虽然它并不是所有操作的最佳选择,但如果你正在制作地图瓷砖或使用只有一个投影的大量标记(点)(例如Mercator,像谷歌Maps和许多其他滑头地图框架),我发现我所谓的“巨大坐标系”真的非常非常方便。基本上,你将x和y像素坐标存储在一些放大的地方——我使用缩放级别23。这有几个好处:

You do the expensive lat/lng to mercator pixel transformation once instead of every time you handle the point Getting the tile coordinate from a record given a zoom level takes one right shift. Getting the pixel coordinate from a record takes one right shift and one bitwise AND. The shifts are so lightweight that it is practical to do them in SQL, which means you can do a DISTINCT to return only one record per pixel location, which will cut down on the number records returned by the backend, which means less processing on the front end.

我在最近的一篇博客文章中谈到了这些: http://blog.webfoot.com/2013/03/12/optimizing-map-tile-generation/

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

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

存储Lat Long值的理想数据类型是十进制(9,6)

这是在大约10cm的精度,而只使用5字节的存储。

例如:CAST(123.456789 as decimal(9,6))