00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 class Geocode extends REST
00012 {
00013 public function __construct($key = null, $base = null)
00014 {
00015
00016 if ($base === null)
00017 $base = 'http:
00018
00019
00020 if (Config::get('yahoo_application_id'))
00021 $key = Config::get('yahoo_application_id');
00022
00023
00024 if ($key !== null)
00025 $base .= "?appid=$key";
00026
00027
00028 parent::__construct($base);
00029 }
00030
00031 public function search($params)
00032 {
00033
00034 if (is_array($params))
00035 {
00036 $params['output'] = 'php';
00037 $data = $this->request($params);
00038 }
00039
00040 else if (is_string($params))
00041 $data = $this->request(array(
00042 'location' => $params,
00043 'output' => 'php'
00044 ));
00045
00046 else
00047 return false;
00048
00049
00050 $real = unserialize($data);
00051
00052
00053 if (!$real)
00054 return false;
00055
00056 else
00057 return $this->parseData($real);
00058 }
00059
00060 public function parseData($data)
00061 {
00062
00063 $geocode['lat'] = $data['ResultSet']['Result']['Latitude'];
00064 $geocode['lon'] = $data['ResultSet']['Result']['Longitude'];
00065
00066
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 ?>