Update! Due to the demand for an easier interface, I have developed a SOAP service offering more functionality and requires less coding on your end. You may see the overview here: http://www.phpfever.com/soap-zip-code-web-service.html.
Ok….
So I’ve created this script based off of the GPS info. It allows you to specify a zip code and radius (in mileage), and it will return the following values in XML:
- stateName
- city
- zipCode
- latitude
- longitude
- distance (from the specified zip code)
- timeZone
It is available via GET at the following URL:
http://www.phpfever.com/web-services/zip_radius.php
There are some GET variables you will have to specify, so read on with a tutorial using CURL.
If you have a script that’s actually going to use this (i.e. dealer locator, dating site), you will probably want to use CURL to get the data necessary.
After making the request, based off of your needs, you will have to parse the XML using your choice of functions/classes provided by PHP or PEAR. Here is a sample script using the CURL extension:
-
<?php
-
-
// URL
-
$zip_code = 42223; // FORT CAMPBELL ZIP CODE
-
$radius = 50; // 50 MILES
-
-
$request_uri =
-
‘http://www.phpfever.com/web-services/
-
zip_radius.php?zip_code=’.$zip_code.‘&radius=’.$radius;
-
-
// Initialize the session
-
$curl = curl_init($request_uri);
-
-
// Set curl options
-
curl_setopt($curl, CURLOPT_HEADER, true);
-
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
-
-
// Make the request
-
$response = curl_exec($curl);
-
-
// Close the curl session
-
curl_close($curl);
-
-
// Get HTTP Status code from the response
-
-
// Check the HTTP Status code
-
switch( $status_code[0] ) {
-
case 200:
-
// Success
-
//print_r($response);
-
break;
-
case 503:
-
break;
-
case 403:
-
break;
-
case 400:
-
break;
-
default:
-
// Unknown error code. Just print it out
-
}
-
-
// Get the XML from the response, bypassing the header
-
-
$xml = null;
-
}
-
-
// Output the XML
-
echo $xml;
-
?>
That’s all it takes. I will be working on other scripts for exporting in a different manner. In the meantime, XML is always a good option (better than nothing).


William : 08 December 2006 at 5:03 pm
Do you know where i could get my GPS service by cell phones?
my friends download GPS software to cell phones, and their phone become the navigation system. so cool! but, how i can get
one too?!
will.fitch : 11 December 2006 at 5:32 pm
http://www.google.com/gmm is one option. This tutorial is actually meant for those who want to host GPS capabilities on their website.
Zip Code Proximity Search | SomeoneFun.com : 12 December 2006 at 10:23 am
[...] I found an excellent API at phpfever.com and am working to implement a ZIP code proximity search on this site with it. [...]
Teerawut : 03 July 2007 at 2:49 am
Good
Kaori D'Alessio : 19 July 2007 at 1:18 am
how do i use the zipcodes by radius service from asp.net? i get a strange error all the time saying that type text/html was returned when type text/xml was expected. is this a security issue.
will.fitch : 26 July 2007 at 6:21 pm
Hi Kaori,
I will be implementing a SOAP service tonight for you to use. For all others, I will be removing the REST service for the newer, better SOAP method.
MOBY : 10 August 2007 at 4:24 am
Bookmarks…
I can’t add your post to Digg. How I do this?…