geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nested lat/lng column names

NomNomCameron opened this issue · comments

Instead of the lat and lng columns having to be directly accessible on the table using chain notation (e.g. Location.lat), is there any current support (or would it be useful to someone other than me) to have the ability to specify accessing the lat lng data from a nested attribute (json for example)?

Something like House.location["lat"] is what I'm looking for

This is almost certainly not going to be supported or possible.

Keep in mind to do what your asking would required deserializing every single JSON object in your database every time you try to perform a query. Imagine if you have 100,000 records in the database, every time you try to find something near a certain latitude and longitude you have to deserialize the JSON data to get the latitude and longitudes to compare to, which would be impractically slow. The slowness will increase by several orders of magnitude the more records you have. If you have just the limited data set, you could write a function to deserialize these yourself and make a comparison, but your best bet is to make these direct attributes of your model/table columns.

Postgres supports jsonb, along with indexing these columns. What deserialization would have to take place in order to lookup lat and lng from a jsonb column type?

I didn't know that about postgres. Can you tell me, is it's use supported elsewhere by rails? IE, can you do this:

Person.where("person.location.lat = ?", latitude)

Or, more railsy, Person.where(location_latitude: latitude)