This is a simple class which uses the the Google Geocoding API to find out a location information based on the zip code. You will get the following using this class:

  • City
  • State
  • Country
  • Longitude
  • Latitude

I have tested it with US and Canadian zip codes.

 

Example:

 

include 'GoogleAddressLookup.php';
 
$zipCode = 60061;
 
$lookup = new GoogleAddressLookup();
$lookup->setZipCode($zipCode);
 
echo 'City: ' . $lookup->getCity() . '('. $lookup->getCityShortName().')<br>';
echo 'State: ' . $lookup->getState() . '('. $lookup->getStateShortName().')<br>';
echo 'Country: ' . $lookup->getCountry() . '('. $lookup->getCountryShortName().')<br>';
echo 'LAT: ' . $lookup->getLatitude().'-- LNG: ' . $lookup->getLongitude();
 

Add new comment