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.