Friday, 25 January 2013

Latitude and longitude in Rails activerecord

I needed to store latitude and longitude in my Postgres db in a way that maintained accuracy of data but also allowed fast efficient searching of this spatial data using BETWEEN queries. The PostGIS extension was not available to me.

The suitable data type for this is a decimal with precision of 9 and scale of 6 [decimal(9,6)]. The activerecord migration code for this turned out to be thus:
add_column :livetokens, :latitude, :decimal, :precision => 9, :scale => 6

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!