Forum: Ruby on Rails ZipCode Search

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6b0c19736485e2f81d70313b9b4ba947?d=identicon&s=25 Chris Williams (Guest)
on 2006-05-08 18:02
I've looked through the messages regarding implementing a ZipCode search
and I have a few questions to make sure I have my head wrapped around
this.

Here's what I have. I have a database table called zipcodes with the
following info (for example)

30310 Atlanta GA 33.727807 -84.41983 -5 1

That's zip, city, state, latitude, longitude, timezone, and dst.

So when a user comes to my site and they enter in an zip code, I want it
to find all stores within a 20 mile radius of the zip code entered.

The database also includes a table called stores. Address, City, State,
and Zip Code.

The SQL I've found to do this is as follow:

@places = Place.find_by_sql ["select p.* from places p where ((3963.0
* acos(sin(p.latitude/57.2958) * sin(?/57.2958) +
cos(p.latitude/57.2958) * cos(?/57.2958) * cos(?/57.2958 -
p.longitude/57.2958))) < ?)", lat, lat, lon,
distance]

I'm assuming I just modify this SQL to select all the store information
from the database table stores and join it on the zip code database
table using the zip code table latitude, longitude, and 20 (for
distance). Right?
This topic is locked and can not be replied to.