/**
  * @param string $address
  * @param int    $limit
  *
  * @return $this
  */
 public function geocode($address, $limit = 1)
 {
     try {
         $this->addresses = $this->geocoder->limit($limit)->geocode($address);
     } catch (\Geocoder\Exception\NoResult $ex) {
         $this->errorKey = 'no_results';
         $this->error = RootLocator_Errors::noResults();
         PerchUtil::debug(sprintf('Locator: %s', $ex->getMessage()), 'error');
     } catch (\Geocoder\Exception\HttpError $ex) {
         $this->errorKey = 'http_error';
         $this->error = RootLocator_Errors::httpError();
         PerchUtil::debug(sprintf('Locator: %s', $ex->getMessage()), 'error');
     } catch (\Geocoder\Exception\InvalidCredentials $ex) {
         $this->errorKey = 'invalid_credentials';
         $this->error = RootLocator_Errors::invalidCredentials();
         PerchUtil::debug(sprintf('Locator: %s', $ex->getMessage()), 'error');
     } catch (\Geocoder\Exception\QuotaExceeded $ex) {
         $this->errorKey = 'quota_exceeded';
         $this->error = RootLocator_Errors::quotaExceeded();
         PerchUtil::debug(sprintf('Locator: %s', $ex->getMessage()), 'error');
     } catch (Exception $ex) {
         $this->errorKey = 'unknown';
         $this->error = RootLocator_Errors::unknown();
         PerchUtil::debug(sprintf('Locator: %s', $ex->getMessage()), 'error');
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function reverse($latitude, $longitude)
 {
     $key = 'geocoder_' . sha1($this->locale . $latitude . $longitude);
     if (false !== ($data = $this->cache->fetch($key))) {
         return unserialize($data);
     }
     $data = $this->provider->reverse($latitude, $longitude);
     $this->cache->save($key, serialize($data), $this->lifetime);
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * Results usually from most accurate to least accurate result (street_address, ..., country)
  *
  * @param float $lat
  * @param float $lng
  * @param array $params
  * @return \Geocoder\Model\AddressCollection Result
  */
 public function reverse($lat, $lng, array $params = [])
 {
     $this->_buildGeocoder();
     $result = $this->geocoder->reverse($lat, $lng);
     if (!$this->_config['allowInconclusive'] && !$this->isConclusive($result)) {
         throw new InconclusiveException(sprintf('Inconclusive result (total of %s)', $result->count()));
     }
     if ($this->_config['minAccuracy'] && !$this->containsAccurateEnough($result)) {
         throw new NotAccurateEnoughException('Result is not accurate enough');
     }
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * Registers a new provider to the aggregator.
  *
  * @param Provider $provider
  *
  * @return ProviderAggregator
  */
 public function registerProvider(Provider $provider)
 {
     $this->providers[$provider->getName()] = $provider;
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * {@inheritDoc}
  */
 public function getName()
 {
     return $this->provider->getName() . '_silenced';
 }