checking the radius in a web site

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

How do I check the radius for a user if they come to my web site and I
want to find out how far certain churches are from where they live.
For instance, display results for churches that are within 25 miles of
where the person lives?

Thank you any help with this.


Re: checking the radius in a web site


Quoted text here. Click to load it

If you are in the US and you have a database of zip codes of all the
known churches, you may want to try any of these classes that provide
solutions for locating the entries that are located within the range of
distance from a given user zip code:

Class: php Zip Locator

Class: Zip Codes Range


Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP /

PHP Reviews - Reviews of PHP books and other products /

Metastorage - Data object relational mapping layer generator

Re: checking the radius in a web site

Quoted text here. Click to load it

Thank you Manuel and everyone else who posted a response to my
question. I've downloaded the Zip Locator class written my Dr. Tarique
Sani and Girish Nair. I also enjoyed Dr. Sani's article in May 2003
PHP | Architect magazine. Thank you Kelvin for that link. This has
been a blast learning how to calculate distances, and I'm grateful for
everyone's input.


Re: checking the radius in a web site

Quoted text here. Click to load it

Some web sites ask for a Zip code (assuming this is in the USA) and
translate this to a set of coordinates for the center of that Zip
code.  Then you calculate the distance between that point and the
known coordinates of the churches to select the close ones.

It may be to your advantage to precalculate some of this, especially
if the radius is ALWAYS 25 miles.  For each church, calculate a
list of Zip codes with a center point within 25 miles.  Populate
the database with that info, and you don't have to do any distance
calculations once you've set up the data.  Just look up the churches
close to the zip code in question.

You can use any coordinate system you want.  For a large radius
(like 1000 miles), you may need to use latitude/longitude degrees
and the appropriate distance formula.  For a smaller radius, where
the curvature of the Earth is not relevant, coordinates on any map
grid and the usual distance formula:

    r = (x2-x1)**2 + (y2-y1)**2

is fine.

I have heard rumors of a Zip-code-to-coordinates database.  I think
the info in the Bureau of the Census TIGER data could be used to
derive one, but it's really too detailed for direct use (but it
could possibly be used to translate street addresses to coordinates
at the street block level, but it likely requires a very clever
parser).  TIGER data for some of the larger counties in Texas is
2-4 megabytes of .zip file.

                        Gordon L. Burditt

Re: checking the radius in a web site

Quoted text here. Click to load it

This was covered in the php|architect magazine in the May 2003 issue.
The issue can be downloaded for free on their website at

Mail is certified Virus Free.
Checked by AVG anti-virus system ( ).
Version: 6.0.778 / Virus Database: 525 - Release Date: 15/10/2004

Site Timeline