• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

zipcodes within milage

Guest
Jun 28, 2007 Jun 28, 2007

Copy link to clipboard

Copied

Hi ,
For example I would like to find TACO BELL with in 20 mile radius. I can i build the program search on zipcode and radius.
Thanx
TOPICS
Advanced techniques

Views

570

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 28, 2007 Jun 28, 2007

Copy link to clipboard

Copied

> For example I would like to find TACO BELL with in 20 mile radius.

Are you only interested in Taco Bell? What about Burger King?

There are two setups you need to do:
- Get the zip codes for every Taco Bell in the country and put them in a database.
- Then download the latitude and longitude zip code directory from http://www.zipcoderesearch.com/geo.html ($49.99).

I presume the user would enter an address, including a zip code, and the number of miles for the radius, correct? Use the zip code directory to obtain the latitude and longitude of the user's address.

Do some trigonometry on the user's lat/long and use the directory to create a list of acceptable zip codes within the desired radius. Then query the database using the list of acceptable zips.

(There's a lot of assuming goin' on here. 🙂 )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 28, 2007 Jun 28, 2007

Copy link to clipboard

Copied

Here is one that works pretty well for me. Just make sure you have all the longs and lats to the corresponding zip.

SELECT a.zipcode, b.zipcode, 3963.0 * acos(sin(a.latitude/57.2958) * sin(b.latitude/57.2958) + cos(a.latitude/57.2958) * cos(b.latitude/57.2958) * cos(b.longitude/57.2958 - a.longitude/57.2958)) AS distance
FROM zipcode a, zipcode b
WHERE a.zipcode = '90210' <==Enter zip here
AND 3963.0 * acos(sin(a.latitude/57.2958) * sin(b.latitude/57.2958) + cos(a.latitude/57.2958) * cos(b.latitude/57.2958) * cos(b.longitude/57.2958 - a.longitude/57.2958)) <= 20 <==Enter miles here
GROUP BY distance;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 28, 2007 Jun 28, 2007

Copy link to clipboard

Copied

Thanx. Do you have any sample code I can test. I have no idea how does that work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 28, 2007 Jun 28, 2007

Copy link to clipboard

Copied

Not anything that is publicly accessable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 28, 2007 Jun 28, 2007

Copy link to clipboard

Copied

could you please let me know what do you have in you db.

I copy one zip db. It looks like that.

"00501","+40.922326","-072.637078","HOLTSVILLE","NY","SUFFOLK","UNIQUE"

I have my db. I have zip code column in it. So I have to match my query to zip file. Is that right.? Thanx

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 28, 2007 Jun 28, 2007

Copy link to clipboard

Copied

With the example query I posted, all you will need is a column for the zipcodes, latitudes and longitudes. Anything else is up to you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 28, 2007 Jun 28, 2007

Copy link to clipboard

Copied

so you have two different zipcode table right?
OR just you joining one table two times.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 29, 2007 Jun 29, 2007

Copy link to clipboard

Copied

LATEST
Its just one table.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation