[英]data type of longitude and latitude to store in mysql database?
I'm designing a table in mysql that will store a list of users and a Google Maps co-ordinate (longitude & latitude). 我正在设计一个mysql表,用于存储用户列表和Google Maps坐标(经度和纬度)。
Will I need two fields, or can it be done with 1? 我需要两个字段,还是可以用1完成?
I don't know what I use? 我不知道我用的是什么? what I use float or decimal or GEOMETRY or there is new data type?
我使用float或decimal或GEOMETRY还是有新的数据类型? what are the pros and cons of the best data type to choose it?
选择最佳数据类型的优缺点是什么?
You can use spatial extensions in mysql the datatype is POINT 您可以在mysql中使用空间扩展 ,数据类型为POINT
It will be faster in search , and many features for geographic operation. 它将更快地进行搜索,并具有许多地理操作功能。
A proper way, and fast, is described on this blog: 这篇博客描述了一种正确的方法,而且速度很快:
http://www.rooftopsolutions.nl/blog/229 http://www.rooftopsolutions.nl/blog/229
CREATE TABLE geo (
longitude DOUBLE,
latitude DOUBLE,
idxlong SMALLINT,
idxlat SMALLINT,
INDEX (idxlong,idxlat);
);
Part 2 contains a benchmark: http://www.rooftopsolutions.nl/blog/230 第2部分包含一个基准: http : //www.rooftopsolutions.nl/blog/230
method small medium large
plain select 1.73s
index on latitude 0.72s
using point field 9.52s
using point field + spatial index 0.00s 0.73s 18.82s
using morton number 0.78s
index on morton 0.00s 0.65s 3.23s
Also a part 3 with in practice: http://www.rooftopsolutions.nl/blog/231 也是实践中的第3部分: http : //www.rooftopsolutions.nl/blog/231
You can use: 您可以使用:
DECIMAL(11, 8)
(3 digits before and 8 digits after decimal) DECIMAL(11, 8)
(前三位数和十进制后八位数) FLOAT
FLOAT
Note that a decimal column can store an exact value, where as a float column stores an approximation of the value. 请注意,十进制列可以存储精确值,其中float列存储值的近似值。 For example
1.999999
will be stored as 1.999999
in the decimal column but as 2.0
in the float column. 例如,
1.999999
将在十进制列中存储为1.999999
,但在float列中存储为2.0
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.