Being able to search for nearby items based on zip code

Hello everyone,

I am building a site which is a searchable directory of doctors.
Basically, doctors can register where their clinic is (address) and then
patients can search and find clinics. I have the tables set up and
everything with a Doctor containing a street, zip code, state, etc. I
simply need a method of allowing a patient to type in a zip code or city
and the have all the nearest doctors in the database displayed to them
sorted by distance.

So basically, I have a database of doctors with their addresses and I
want to have the patient type in a zip code or city (and a radius) and
then I need to perform a query which will give me a list of the closest
X doctors in order by distance from that zip code.

Problem is I wouldn’t know where to begin to actually code the algorithm
myself. I assume you would need a huge table of every zip code and maybe
the latitiude and longitude and then calculate the distances or
something. I would much prefer to use a library or purchase a package
that can do this.

This has GOT to be a hugely common requirement to be able to search for
“X’s close to address Y within Z radius sorted by distance”. This seems
like a very common configuration and I would love an experts advice on
whats the “best” route to use for this. Obviously I want it to be
efficient as possible but also be easy to implement.

Thanks in advance for your suggestions.

On Aug 29, 10:41 pm, Nathan E. <rails-mailing-l…@andreas-
s.net> wrote:

So basically, I have a database of doctors with their addresses and I
This has GOT to be a hugely common requirement to be able to search for
“X’s close to address Y within Z radius sorted by distance”. This seems
like a very common configuration and I would love an experts advice on
whats the “best” route to use for this. Obviously I want it to be
efficient as possible but also be easy to implement.

Thanks in advance for your suggestions.

Posted viahttp://www.ruby-forum.com/.

look at the Apress books on Google maps apps (one for Rails, one for
PHP)

Will that book have a very clear guide to doing a search for items in my
database that are near a certain zip code? Is this the book?
http://www.amazon.com/Beginning-Google-Maps-Applications-Rails/dp/1590597877

Anyone willing to help me get started without having to purchase a book?
Surely there is some open source project or code snippet for this common
behavior?

[email protected] wrote:

On Aug 29, 10:41 pm, Nathan E. <rails-mailing-l…@andreas-
s.net> wrote:

So basically, I have a database of doctors with their addresses and I
This has GOT to be a hugely common requirement to be able to search for
“X’s close to address Y within Z radius sorted by distance”. This seems
like a very common configuration and I would love an experts advice on
whats the “best” route to use for this. Obviously I want it to be
efficient as possible but also be easy to implement.

Thanks in advance for your suggestions.

Posted viahttp://www.ruby-forum.com/.

look at the Apress books on Google maps apps (one for Rails, one for
PHP)

Nathan E. wrote:

Hello everyone,

I am building a site which is a searchable directory of doctors.
Basically, doctors can register where their clinic is (address) and then
patients can search and find clinics.
Geocoding is the magic term you want to plug into Google. A quick search
results in this http://geokit.rubyforge.org/ which may do what you want.
There are many providers (free and commercial) of the postcode/zipcode
lat/long details you will need as well.

Cheers,

Anthony

Anthony, thank you. Thanks you again. You are truly a gentleman and a
scholar. Geokit is EXACTLY what I need. For posterity, GeoKit allows you
to perform distance based queries on any table with a lat/lon. For
instance if every doctor has a lat, lon attribute then I can simply
perform this query:

Doctor.find(:all, :origin=>‘92453’, :within=>10)

Thanks again.

Anthony R. wrote:

Nathan E. wrote:

Hello everyone,

I am building a site which is a searchable directory of doctors.
Basically, doctors can register where their clinic is (address) and then
patients can search and find clinics.
Geocoding is the magic term you want to plug into Google. A quick search
results in this http://geokit.rubyforge.org/ which may do what you want.
There are many providers (free and commercial) of the postcode/zipcode
lat/long details you will need as well.

Cheers,

Anthony

If what you are doing is OpenSource Nathan would you be so kind to
write a blog entry about it?

On Aug 30, 10:26 am, Nathan E. <rails-mailing-l…@andreas-

Anyone willing to help me get started without having to purchase a book?
Surely there is some open source project or code snippet for this common
behavior?

Maybe take a look at:

http://www.sanisoft.com/phpziplocator

It’s PHP, Lesser GNU General Public License. It’s been a while
(year’s?), but if I recall it wasn’t too difficult to take the database
table provided and use the PHP examples as a basis for what I was trying
to accomplish.

Thank you for finding an alternative david. The big difference between
geokit and this one is that geokit is using google api’s to do
everything behind the scenes while this method you linked to does it all
from my own server. Once my application begins to scale, I may very well
switch to this method because it allows me to do it all without
requiring external api’s. So, again, thanks for finding me exactly what
I needed!

As for writing a blog entry, I doubt you would be interested. I have
only been working with rails for a month or so now and this is my first
project I am doing in it which will to be deployed to the public. Not
to mention that right now all I have is paper prototypes and a set of
milestones for the project. I appreciate the offer though!

David Andrew T. wrote:

I came across http://zipcodesearch.rubyforge.org/ but geokit looks like
it
may be a more robust solution.

On 8/30/07, unimatrixZxero [email protected] wrote:

instance if every doctor has a lat, lon attribute then I can simply

I am building a site which is a searchable directory of doctors.

Anthony


Posted viahttp://www.ruby-forum.com/.


David Andrew T.
http://dathompson.blogspot.com

I came across http://zipcodesearch.rubyforge.org/ but geokit looks like
it
may be a more robust solution.

On 8/30/07, unimatrixZxero [email protected] wrote:

instance if every doctor has a lat, lon attribute then I can simply

I am building a site which is a searchable directory of doctors.

Anthony


Posted viahttp://www.ruby-forum.com/.


David Andrew T.
http://dathompson.blogspot.com