Suppose I have all zip codes database, how may I allow my users search all things within xxx miles from his/her zip codes? I have no idea on the calculation of the math. anyone may help me with same codes? Thanks in advance. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 9/12/07, Surfman Joe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Suppose I have all zip codes database, how may I allow my users search > all things within xxx miles from his/her zip codes? I have no idea on > the calculation of the math. anyone may help me with same codes? Thanks > in advance.You''d probably be best off looking at one of the geocoding plugins available for rails. GeoKit, acts_as_geocode and acts_as_locateable all provide this functionality. http://jystewart.net/process/2007/03/comparing-rails-geo-plugins/ James. -- James Stewart - Web Developer Work : http://jystewart.net Play : http://james.anthropiccollective.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Surfman Joe wrote:> Suppose I have all zip codes database, how may I allow my users search > all things within xxx miles from his/her zip codes? I have no idea on > the calculation of the math. anyone may help me with same codes? Thanks > in advance.a book named RailsSpace: Building a Social Networking Website with Ruby on Rails have a chapter dealing with the same problem. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Owen van Dommelen
2007-Sep-12 12:41 UTC
Re: how to calculate the distance/radius on zipcodes?
Surfman Joe wrote:> Suppose I have all zip codes database, how may I allow my users search > all things within xxx miles from his/her zip codes? I have no idea on > the calculation of the math. anyone may help me with same codes? Thanks > in advance.As I recall you can use Pythagoras (is this correct spelling in English?) for this purpose. Let me know, I might be able to find the query I used for this a while ago. At the moment I am also using a gem for this: GeoRuby. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, You can find usefull information on http://en.wikipedia.org/wiki/ Haversine_formula. Hope that helps. JP Antunes http://open-mind-open-opinion.blogspot.com On Sep 12, 2007, at 1:41 PM, Daniel Owen van Dommelen wrote:> > Surfman Joe wrote: >> Suppose I have all zip codes database, how may I allow my users >> search >> all things within xxx miles from his/her zip codes? I have no idea on >> the calculation of the math. anyone may help me with same codes? >> Thanks >> in advance. > > As I recall you can use Pythagoras (is this correct spelling in > English?) for this purpose. Let me know, I might be able to find the > query I used for this a while ago. At the moment I am also using a gem > for this: GeoRuby. > > -- > Posted via http://www.ruby-forum.com/. > > >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFG6CAA8Q7LSJzhNq4RAiSSAJ9rt6Yu0wUEiqOio3KlZAi2x1yQrACbB6Bc Ky0T98x6I4dPJ2KGBf3iG2k=qTYF -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Surfman Joe wrote:> Suppose I have all zip codes database, how may I allow my users search > all things within xxx miles from his/her zip codes? I have no idea on > the calculation of the math. anyone may help me with same codes? Thanks > in advance.Here''s a calculation that selects all zip codes within 50 miles (80.465 kilometers) from zip 01516 (longitude: -71.70485213724869, latitude: 42.04027444338595) http://pastie.caboo.se/97232 Things to note: 1.) The zipcode table has three columns: zc_zip, the column for the 5-char zip code; zc_lat, the latitude of the zip code; zc_lon, for the longitude. 2.) The query returns a list of zip codes within the specified radius 3.) The value 80.465 at the end of the query is the distance in kilometers that you are searching. (To convert US miles to kilometers multiply by 1.6093, i.e. 50 mi * 1.6093 = 80.465 km) 4.) I don''t claim to understand it, I just know that it works http://pastie.caboo.se/97232 You can get a list of all US Zip codes with lat/lon values from http://www.census.gov/geo/ZCTA/zcta.html. However, since this works on lat/lon data it is not limited to just US zip codes. If you know the starting lat/lon you can search any other lat/lon pairs in your DB. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---