简体   繁体   English

要存储在mysql数据库中的经度和纬度的数据类型?

[英]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: 您可以使用:

  • a pair of DECIMAL(11, 8) (3 digits before and 8 digits after decimal) 一对DECIMAL(11, 8) (前三位数和十进制后八位数)
  • a pair of 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.

相关问题 将经纬度插入MySQL数据库 - Inserting latitude and longitude into MySQL database 如何使用自动完成功能在mysql数据库上获取经度和纬度 - How to get latitude and longitude on mysql database with autocomplete 在 MySQL 数据库中存储纬度和经度值时出现问题 - Problem Storing Latitude and Longitude values in MySQL database 从纬度和经度到mysql数据库附近 - get nearby from mysql database with latitude and longitude 需要使用PHP将Android应用程序生成的纬度和经度值存储到mySQL数据库中 - Need to store the latitude and longitude values generated from android app into mySQL database using PHP 编写 Laravel 迁移以创建数据类型为 point 的 postgres 表列,用于存储纬度经度(坐标) - Write Laravel Migration to create postgres table column with data type point for to store latitude longitude (coordinates) Laravel 店铺经纬度 - Laravel store latitude and longitude 在数据库中插入经度 - insert latitude longitude in database MariaDB 和 MySQL POINT 类型:纬度和经度按什么顺序返回? - MariaDB and MySQL POINT type: In which order are Latitude and Longitude returned? 在MySQL数据库的纬度/经度矩形内查找项目的优雅方法? - Elegant way of finding items within a latitude / longitude rectangle in an MySQL database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM