GPS坐标的浮点数或小数点

GPS坐标的浮点数或小数点

本文介绍了Rails 3 GPS坐标的浮点数或小数点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将GPS坐标存储在数据库中。我听说花车不如小数准确。真的吗?如果是这样,有什么理由是曾经使用浮动?

解决方案

如果你想要更精确的GPS坐标,然后是小数是要走的路。你可以使用如下的迁移来创建它们:

  create_tablemodelsdo | t | 
t.decimallatitude,:precision => 15,:scale => 10,:default => 0.0
t.decimallongitude,:precision => 15,:scale => 10,:default => 0.0
end

人们使用浮动的原因是它们通常足够精确,案件和使用较少的空间来存储。


I need to store GPS coordinates in a database. I've heard that floats are less accurate than decimals. Is that true? If so, what reason is there to ever use floats?

解决方案

If you want more accurate GPS coordinates, then yes decimals are the way to go. You can create them with a migration like:

create_table "models" do |t|
  t.decimal  "latitude", :precision => 15, :scale => 10, :default => 0.0
  t.decimal  "longitude", :precision => 15, :scale => 10, :default => 0.0
end

The reason people use floats is that they are usually precise enough for most use cases and use less space to store.

这篇关于Rails 3 GPS坐标的浮点数或小数点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:53