I am using graticule but could not figure out how to find something
say within a distance of 50 miles? I am clueless how to even start
this. I wonder if this group is still active but if it is could
someone please help me out??
-Daniel
--
Daniel Morrison
[i] Collective Idea
http://collectiveidea.com
http://ideafoundry.info
25 West 8th Street, Suite 200
Holland, MI 49423
616-990-0155
dan...@collectiveidea.com
Here is my code :-
geo_search.rb
module GeoSearch
def sql_for_distance(origin)
Graticule::Distance::Spherical.to_sql(
:latitude => origin[0],
:longitude => origin[1],
:latitude_column => "`locations`.`geo_lat`",
:longitude_column => "`locations`.`geo_lng`",
:units => :kilometers
)
end
end
in event.rb
def self.all_with_distance(origin)
distance_sql = sql_for_distance(origin)
select("#{table_name}.*, #{distance_sql} AS
distance").select("`locations`.`geo_lat`, `locations`.`geo_lng`,
`locations`.`name` as location_name").joins(:location)
end
In my event controller I have this code which gives me the listing of
the events based on the distance
@events = Event.all_with_distance([current_user.geo_lat,
current_user.geo_lng]).where("private = ? AND start > ?", false,
Time.zone.now).order("distance").order("start DESC").limit(5)
I want to find users withing 50 miles to the event.
Thanks,
No clue how to do it.
On Dec 10, 7:08 pm, Daniel Morrison <dan...@collectiveidea.com> wrote:
> Sure, are you using it with Rails (and acts_as_geocodable)? If not, what are the objects you want to find?
>
> -Daniel
>
> --
> Daniel Morrison
> [i] Collective Ideahttp://collectiveidea.comhttp://ideafoundry.info
It uses a lot of math to pull it off. The queries aren't the easiest to grok, but they aren't hard to work with.
See:
https://github.com/collectiveidea/acts_as_geocodable/blob/master/lib/acts_as_geocodable.rb#L64
-Daniel
--
Daniel Morrison
[i] Collective Idea
http://collectiveidea.com
http://ideafoundry.info
25 West 8th Street, Suite 200
Holland, MI 49423
616-990-0155
dan...@collectiveidea.com
Is there a good tutorial for acts_as_geocodable ? The resource on the
github link is not providing lot of information on how to use it.
and if I want to use acts_as_geocodable I hope there are not lot of
changes which I have to make in the existing app.
On Dec 10, 8:09 pm, Daniel Morrison <dan...@collectiveidea.com> wrote:
> acts_as_geocodable is designed to do this, but you could just look at the code and copy the queries it uses.
>
> It uses a lot of math to pull it off. The queries aren't the easiest to grok, but they aren't hard to work with.
>
> See:
>
> https://github.com/collectiveidea/acts_as_geocodable/blob/master/lib/...
If I do something like this :-
@users = User.all
@users.each do |u|
@events = Event.all(:within => 20, :origin =>
([u.geo_lat,u.geo_lng]))
:origin => expects only one argument what are my options here?
Thanks,
Akram