Exemplo n.º 1
0
 function geoCode($gapikey, $address, $cache = null)
 {
     // use cache result
     if ($cache !== null && ($value = $cache->get($address))) {
         if (ereg('([0-9.-]{1,}),([0-9.-]{1,})', $value, $regs)) {
             return array('lat' => $regs[1], 'lng' => $regs[2]);
         }
     }
     // query google maps geocoder and parse result
     $result = modYOOmapsHelper::queryGeoCoder($gapikey, $address);
     $coordinates = null;
     if (ereg('<coordinates>([0-9.-]{1,}),([0-9.-]{1,}).*</coordinates>', $result, $regs)) {
         $coordinates = array('lng' => $regs[1], 'lat' => $regs[2]);
     }
     // cache geocoder result
     if ($cache !== null && $coordinates !== null) {
         $cache->set($address, $coordinates['lat'] . "," . $coordinates['lng']);
     }
     return $coordinates;
 }