Forum: Ruby on Rails ZipCode Search

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Chris W. (Guest)
on 2006-05-08 20: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

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,

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.