geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.
MIT License
1.57k stars 245 forks source link

Search on two different locations #112

Closed pastullo closed 3 years ago

pastullo commented 7 years ago

Is it possible to search on two different locations?

I need to search all records within a destination as well as an arrival place. Is this possible? I couldn't find a way

mnoack commented 7 years ago

In the readme is says "ActiveRecord distance-based finders. For example, you can find all the points in your database within a 50-mile radius."

I'm not sure what you mean as destination AND arrival place, could you give me a more specific scenario and why it is useful and maybe I can understand the situation and advise.

If that functionality doesn't exist and you implement it, you're welcome to submit that feature for inclusion in the gem.

Is that what you mean, that's basically the core ActiveRecord feature of geokit-rails.

pastullo commented 7 years ago

Hey @mnoack sure.

I have Trip object, which leaves from one place and arrives to another place. The fields are _from_lat, from_lng, to_lat, tolng.

I am building a search feature and need to be able to use the active records finders on both location. How would you do this?

pastullo commented 7 years ago

hey @mnoack to give you more info, i have this model: Ride.new({ from_lat: 1, from_lng: 1, to_lat: 1, to_lng: 1 })

So each ride has a from and a to location.

I need to be able to do something like:

Ride
  .within(10, origin: from, column_lat_name: :from_lat, column_lng_name: :from_lng)
  .within(10, origin: to, column_lat_name: :to_lat, column_lng_name: :to_lng)

You can only define the :column_lat_name in the model, but ideally you should be able to swap it on the fly! Any ideas?

ryankopf commented 3 years ago

Currently, and I think going forward, you will have to do this with two separate requests.

r_1 = Ride .within(10, origin: from, column_lat_name: :from_lat, column_lng_name: :from_lng).pluck(:id) r_2 = Ride .within(10, origin: to, column_lat_name: :from_lat, column_lng_name: :from_lng).pluck(:id) Ride.where("id IN (?)",r1+r2)