我正在处理地图数据,纬度/经度扩展到小数点后8位。例如:
Latitude 40.71727401
Longitude -74.00898606
我在谷歌文档中看到的 它使用:
lat FLOAT( 10, 6 ) NOT NULL,
lng FLOAT( 10, 6 ) NOT NULL
但是,它们的小数点后只到6。 我应该使用FLOAT(10,8)还是有其他方法来存储这些数据,以便它是精确的。它将用于地图计算。谢谢!
我正在处理地图数据,纬度/经度扩展到小数点后8位。例如:
Latitude 40.71727401
Longitude -74.00898606
我在谷歌文档中看到的 它使用:
lat FLOAT( 10, 6 ) NOT NULL,
lng FLOAT( 10, 6 ) NOT NULL
但是,它们的小数点后只到6。 我应该使用FLOAT(10,8)还是有其他方法来存储这些数据,以便它是精确的。它将用于地图计算。谢谢!
当前回答
在rails上使用迁移ruby
class CreateNeighborhoods < ActiveRecord::Migration[5.0]
def change
create_table :neighborhoods do |t|
t.string :name
t.decimal :latitude, precision: 15, scale: 13
t.decimal :longitude, precision: 15, scale: 13
t.references :country, foreign_key: true
t.references :state, foreign_key: true
t.references :city, foreign_key: true
t.timestamps
end
end
end
其他回答
在laravel中使用十进制列类型进行迁移
$table->decimal('latitude', 10, 8);
$table->decimal('longitude', 11, 8);
有关更多信息,请参阅可用的列类型
在rails上使用迁移ruby
class CreateNeighborhoods < ActiveRecord::Migration[5.0]
def change
create_table :neighborhoods do |t|
t.string :name
t.decimal :latitude, precision: 15, scale: 13
t.decimal :longitude, precision: 15, scale: 13
t.references :country, foreign_key: true
t.references :state, foreign_key: true
t.references :city, foreign_key: true
t.timestamps
end
end
end
你应该简单地使用varchar (20)
MySQL支持空间数据类型,Point是可以使用的单值类型。例子:
CREATE TABLE `buildings` (
`coordinate` POINT NOT NULL,
/* Even from v5.7.5 you can define an index for it */
SPATIAL INDEX `SPATIAL` (`coordinate`)
) ENGINE=InnoDB;
/* then for insertion you can */
INSERT INTO `buildings`
(`coordinate`)
VALUES
(POINT(40.71727401 -74.00898606));
不要使用浮动…它会环绕你的坐标,导致一些奇怪的现象。
使用十进制