has_finder and Geokit

I have recently discovered the brilliant has_finder. It allows you to
name your ActiveRecord searches,
and stack them together. It fulfills a similar need to scope_out.

One of my searches is location based, using the excellent plugin
Geokit.
http://geokit.rubyforge.org/. Normally I can do a spatial search like
so:

MyModel.find(:all, :origin => [lat, lng], :within => miles_in_int)

When I try to do this within a has_finder finder (see below), it
complains
:origin and :within can not be find. It must be accessing the finder
methods
directly without going through Geokit.

has_finder :proximity, lambda {|lat, lon| { :origin => [lat,
lon], :within
=> 100 } }

normal has_finder
has_finder :of_type, lambda {|type_id| { :conditions =>
{:feature_type_id =>
type_id} } }

I am not sure how it all works under the hood. Can anyone advice on
getting this to work? Any pointers would really help.

I'll take a look at the source code in the mean time.

Thanks,
Xin

It would be nice if this would work. I'm using GeoKit with named_scope
in Rails 2.1.

Mark Jameson wrote:

It would be nice if this would work. I'm using GeoKit with named_scope
in Rails 2.1.

I got this working and it was really easy.

Models with "acts_as_mappable" have a method for distance_sql(origin,
units=default_units, formula=default_formula). I used this to create my
condition.

I am using anonymous scopes in a Search model which provides search for
an Organization model, but a similar technique should work with
named_scope. See this Railscast on creating a search with anonymous
scopes: http://railscasts.com/episodes/112-anonymous-scopes

I have "acts_as_mappable" on both my Search model and on my Organization
model. This allows me to build a scope condition like this:

scope = scope.conditions "#{Organization.distance_sql(self)} <
#{self.distance}"

Note that "self" is the search in this case.

I hope this helps.

BB