Open keithnorm opened 11 years ago
I'm looking for the same advice. I have a very similar model and am looking at the various gems, and am not finding any good answers. Especially when I want to chain those queries together and find an origin within one radius and the destination within another. Did you get any where with this?
I punted on it for now and am working around it in my project.
I think it's worth a fork / pull request to add it into geokit-rails and I may work on that still, but it would be cool to get a "yeah that's a good idea" from the geokit-rails team before doing that work.
Without doing any work to geokit-rails, I think something like this would work technically
origin_location_ids = Location.select(:id).within(50, [origin_lat, origin_lng])
destination_location_ids = Location.select(:id).within(50, [destination_lat, destination_lng])
trips = Trip.where(:destination_location => destination_location_ids, :origin_location => origin_location_ids)
but I think that's ugly and not sure if it has scaling or other problems.
Just curious how you guys would handle a scenario like this:
Say you have a Trip model and a Trip has an origin_location and a destination_location. Hypothetically something like:
And I'm kind of thinking I want to make calls like:
Trip.destination_location_within(50, [lat, lng])
andTrip.origin_location_within(50, [lat, lng])
Do you think that makes sense, or should this instead be modeled differently? Any insight / advice on how to handle this situation?
Thanks!