[ACCEPTED]-Correct datatype for latitude and longitude? (in activerecord)-types
This is what I use:
add_column :table_name, :lat, :decimal, {:precision=>10, :scale=>6}
add_column :table_name, :lng, :decimal, {:precision=>10, :scale=>6}
0
If you need to do more complex geographical 7 calculations, you can investigate PostGIS for Postgresql 6 or MySQL Spatial Extensions for MySQL. Otherwise, a float (double 5 precision might be a good idea) should work.
Edit: It 4 looks like the GeoRuby library includes a Rails 3 extension for working with the spatial/GIS 2 extensions for both of the aforementioned 1 databases.
If you're not using a spatially-enabled 4 database, Google Maps recommends using floats of size 3 (10,6). That gives you 6 digits after the 2 decimal - if you want more precision, you 1 can adjust accordingly.
I would suggest using floats, although it 3 doesn't really make that much of a difference. Floats 2 are easier to do calculations on if you 1 ever desire that in the future.
Generally you want Lat/Long stored in the 7 largest float type you have. At some latitudes 6 (eg: near the equator) very small changes 5 in longitude can equate to large differences 4 in terms of surface distance.
I suppose if 3 it is a field which you won't ever want 2 to do any math on, you could use a string. I'd 1 avoid that though.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.