/** * Geocode an address using defined providers * * @param string $address * @param bool $refresh_cache * @return Geocoder\Model\Address */ public static function geocodeAddress($address, $refresh_cache = false) { // Cache support if (self::config()->cache_enabled) { $cache = self::getCache(); $cache_key = md5($address . i18n::get_locale()); if ($refresh_cache) { $cache_result = $cache->load($cache_key); if ($cache_result) { return unserialize($cache_result); } } } try { $result = self::getGeocoder()->geocode($address); if ($result instanceof \Geocoder\Model\AddressCollection) { $result = $result->first(); } if ($result && self::config()->cache_enabled) { $cache->save(serialize($result), $cache_key, array('address'), null); } return $result; } catch (Exception $e) { $level = SS_Log::WARN; if ($e instanceof \Geocoder\Exception\CollectionIsEmpty) { $level = false; } if ($e instanceof \Geocoder\Exception\NoResult) { $level = false; } if ($level) { SS_Log::log($e->getMessage(), $level); } self::$lastException = $e; return false; } }