Search code examples
ruby-on-rails-3postgispostgresql-9.3

How Can i return Longitude and latitude from a point RGEO Postgis


I have a table in my database with location city, state, zip, and a point

the point in my database looks like this 0101000020E6100000000000E0087B52C0000000402F6B4440

When i run this command i get this:

1.9.3-p547 :014 > coords = "ST_GeographyFromText('#{Location.first.coords}')"
2014-09-08 11:46:55 DEBUG --   Location Load (77.4ms)  SELECT "locations".* FROM "locations" LIMIT 1
=> "ST_GeographyFromText('POINT (-85.28800201416016 48.596500396728516)')" 

what i want to do if figure out how to pull and set each latitude and longitude from that

   Latitude = "48.596500396728516"
   Longitude = "-85.28800201416016"

I need these so i can use it with Google maps...


Solution

  • Use ST_Y(geom) for latitude and ST_X(geom) for longitude.