Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

geocode.inc.php

Go to the documentation of this file.
00001 <?
00002 /*************************************************
00003 *
00004 *   Geocode PHP Class - Access Yahoo API.
00005 *   Copyright 2006 Zach Smith
00006 *   http://hoeken.ubersonic.org
00007 *   License: GPL
00008 *
00009 *************************************************/
00010 
00011 class Geocode extends REST
00012 {
00013     public function __construct($key = null, $base = null)
00014     {
00015         //heres our base.
00016         if ($base === null)
00017             $base = 'http://api.local.yahoo.com/MapsService/V1/geocode';
00018     
00019         //do we ahve a key set?
00020         if (Config::get('yahoo_application_id'))
00021             $key = Config::get('yahoo_application_id');
00022 
00023         //if its not null... add it in.
00024         if ($key !== null)
00025             $base .= "?appid=$key";
00026         
00027         //set up our rest action
00028         parent::__construct($base);
00029     }
00030 
00031     public function search($params)
00032     {
00033         //did we get an array of params?
00034         if (is_array($params))
00035         {
00036             $params['output'] = 'php';
00037             $data = $this->request($params);
00038         }
00039         //nope, try a manual lookup.
00040         else if (is_string($params))
00041             $data = $this->request(array(
00042                 'location' => $params,
00043                 'output' => 'php'
00044             ));
00045         //its nothing... wtf.
00046         else
00047             return false;
00048 
00049         //get our real data
00050         $real = unserialize($data);
00051         
00052         //if there was an error... the unserialize will have a false value.
00053         if (!$real)
00054             return false;
00055         //nope, return the lat/lon!
00056         else
00057             return $this->parseData($real);
00058     }
00059 
00060     public function parseData($data)
00061     {
00062         //lat and lon are important
00063         $geocode['lat'] = $data['ResultSet']['Result']['Latitude'];
00064         $geocode['lon'] = $data['ResultSet']['Result']['Longitude'];
00065 
00066         //as is city/state/zip/country
00067         $geocode['address'] = $data['ResultSet']['Result']['Address'];
00068         $geocode['city'] = $data['ResultSet']['Result']['City'];
00069         $geocode['state'] = $data['ResultSet']['Result']['State'];
00070         $geocode['zip'] = $data['ResultSet']['Result']['Zip'];
00071         $geocode['country'] = $data['ResultSet']['Result']['Country'];
00072         
00073 
00074         return $geocode;
00075     }
00076 }
00077 ?>

Generated on Fri Oct 27 12:26:40 2006 for BaseJumper by doxygen 1.3.9.1