• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1321
  • Last Modified:

How can I find the nearest 3 zip codes locations from the zip code entered?

I am implementing Google Map Zip Code Search and my previous question here
I have 100 zip codes of US and it is all fixed zip codes with address and to be searched this database by the user to enter zip code only  ...
based on this How can I pull the nearest 3 locations from its database ? I mean nearest 3 zip codes to be find ? Please help me.

At present, my code is implemented just search for single zip code and the details fetched from the db and shown on the google map
0
Loganathan Natarajan
Asked:
Loganathan Natarajan
2 Solutions
 
Jagadishwor DulalBraces MediaCommented:
One of the good way to show exactly nearest 3 zip is adding nearest zip in database so that you can easily manage it.
I don't know about your table structure but may add nearest1, nearest2, nearest3 and zip code for them. But if you want to get zip code by increment no like 1111, 1112, 1113, 1114 when you select 1111 you may create a select query which can retrieve 3 records from current searched record if searched zip found.
0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
I have like this my table structure ?
<test_id>71</test_id>
<zipcode>93030</zipcode>
<test_name>This is name details</test_name>
<details>test</time_details>
<address>5, street</address>
<phone>32443-3244343</phone>
<ultrasound>no</ultrasound>
<spanish>0000</spanish>
<STDcode>0000</STDcode>
<post_test>0000</post_test>
<trals>0000</trals>
<bellas>0000</bellas>
<websiteurl>0000</websiteurl>
<fax>0000</fax>
<rtll>0000</rtll>
<ils>0000</ils>
<besat>0000</besat>
<carenet>0000</carenet>
<county>VC</county>

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
In fact, what I have the zip codes are only California
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Jagadishwor DulalBraces MediaCommented:
Then it's better to use http://www.zipmaps.net/ where it shows zips
0
 
VampireofdarknessCommented:
You will need to either have the latitude and longitude to calculate an 'as the crow flies' distance using the Great Circle calculations (many are available from a quick google search), this will not be precise for drive times though, or to use an API (such as Google Maps) to geocode and calculate the driving distance between the two points then save that to your database in a separate table:

Table: distances
Zip1: xxxxx
Zip2: yyyyy
Distance: zzzzzz

Then you would search for SELECT Zip1,Zip2,Distance FROM distances WHERE Zip1='Zip to search' OR Zip2='Zip to search' ORDER BY Distance ASC Limit 0,3

If you do one-way (x to y and not y to x) you use the above, if you do two-way (calculate x to y and y to x, as it may take different roads) you only need Zip1 in your WHERE clause.

This is the more accurate method and you can cache results, but you will need to set up the database first and Google's API is limited to 2,500 calls in one day for one IP address so depending on the size of your database, it could be infeasible. Google's Premier accounts I think raise this to 100,000 calls in a day.

To get two-way distances (even more accuracy) you'll need more results than one-way. I think it works out to n*(n-1) where n is your number of records (so 10 entries = 90 searches of an API, 8,000 entries = 63,992,000 searches)

Note: If you are using American zip codes, I think there is another service called geocode.us that also allows a certain number of free queries per day. I can't remember if that has an API though.
0
 
Ray PaseurCommented:
See if this article can give you the guidance you need.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_4276-What-is-near-me-Proximity-calculations-using-PHP-and-MySQL.html

There are about 42,000 ZIP codes in the US.  Most of the free ZIP-to-address data bases are full of inaccuracies, so be careful to scrub your data.  Best regards, ~Ray
0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
@ Ray_Paseur

Thanks, I will look at it.
0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now