{@inheritdoc}

@see \Concrete\Core\Geolocator\GeolocatorController::performGeolocation()
774564
protected function performGeolocation(AddressInterface $address)
    {
        $configuration = $this->geolocator->getGeolocatorConfiguration();
        $uri = str_replace('[[IP]]', rawurlencode((string) $address), $configuration['url']);
        $httpClient = $this->app->make(HttpClient::class);
        $httpClient->setUri($uri);
        $result = new GeolocationResult();
        try {
            $response = $httpClient->send();
        } catch (Exception $x) {
            $result->setError(GeolocationResult::ERR_NETWORK, t('Request to geoPlugin failed: %s', $x->getMessage()), $x);
        }
        if ($result->hasError() === false) {
            if (!$response->isSuccess()) {
                $result->setError(GeolocationResult::ERR_NETWORK, t('Request to geoPlugin failed with return code %s', sprintf('%s (%s)', $response->getStatusCode(), $response->getReasonPhrase())));
            } else {
                $responseBody = $response->getBody();
                $data = @json_decode($responseBody, true);
                if (
                    !is_array($data)
                    || empty($data['geoplugin_status'])
                ) {
                    $result->setError(GeolocationResult::ERR_LIBRARYSPECIFIC, t('Malformed data received from geoPlugin (%s)', $responseBody));
                } else {
                    switch ($data['geoplugin_status']) {
                        case static::GEOPLUGIN_STATUS_NOTFOUND:
                            break;
                        case static::GEOPLUGIN_STATUS_OK:
                        case static::GEOPLUGIN_STATUS_ONLYCOUNTRY:
                            $this->dataToGeolocationResult($data, $configuration, $result);
                            break;
                        default:
                            $result->setError(GeolocationResult::ERR_LIBRARYSPECIFIC, t('Unknown geoPlugin status code: %s', $data['geoplugin_status']));
                            break;
                    }
                }
            }
        }

        return $result;
    }
1216086
private function mapGeoposResults($results)
    {
        $ret = [];

        foreach ($results as $coords) {
            $point = [];

            foreach ($coords as $latlon) {
                array_push($point, floatval($latlon));
            }

            array_push($ret, $point);
        }

        return $ret;
    }
1135735
public function addressToPoint($address, $region = '')
    {
        // Get the URL for the Mapbox API
        $url = Config::inst()->get(__CLASS__, 'mapbox_api_url');
        $key = Config::inst()->get(__CLASS__, 'mapbox_api_key');

        if (!$url) {
            // If no URL configured. Stop.
            throw new Exception('No mapbox_api_url configured. This is not allowed.');
        }

        if (!$key) {
            // If no KEY configured. Stop.
            throw new Exception('No mapbox_api_key configured. This is not allowed.');
        }

        // Add params
        $queryVars = [
            'access_token' => $key,
            'type' => 'address',
        ];
        if ($region) {
            $queryVars['country'] = $region;
        }
        $url .= urlencode($address).'.json?'.http_build_query($queryVars);

        $client = new Client();
        $response = $client->get($url);
        if (!$response) {
            throw new GeocodeServiceException('No response.', 0, '');
        }
        $statusCode = $response->getStatusCode();
        if ($statusCode !== 200) {
            throw new GeocodeServiceException('Unexpected status code:'.$statusCode, $statusCode, '');
        }
        $responseBody = json_decode((string)$response->getBody());

        // Error handling
        if ($responseBody) {
            if (isset($responseBody->message)) {
                throw new GeocodeServiceException('Error message: '.$responseBody->message, $statusCode, $responseBody);
            }
            if (!isset($responseBody->features) || !count($responseBody->features) === 0) {
                throw new GeocodeServiceException('Zero results returned. Invalid status from response: '.$status, $statusCode, $responseBody);
            }
        } else {
            // Fallback to full string dump
            $text = trim($response->getBody());
            throw new GeocodeServiceException('Invalid response: '.$text, $statusCode, $responseBody);
        }

        // We take the first match, because that's most likely the best match
        $feature = reset($responseBody->features);
        list($lng, $lat) = $feature->geometry->coordinates;

        return [
            'lat' => (float)$lat,
            'lng' => (float)$lng
        ];
    }
657219
public function geolocateIPAddress(AddressInterface $address)
    {
        $result = new GeolocationResult();
        try {
            switch ($address->getRangeType()) {
                case IPRangeType::T_PUBLIC:
                    $addressString = (string) $address;
                    $session = $this->app->make('session');
                    $sessionKey = 'ccm/geolocation/' . $this->geolocator->getGeolocatorHandle() . '/' . $this->geolocator->getGeolocatorID() . '/' . md5(serialize($this->geolocator->getGeolocatorConfiguration())) . '/' . $addressString;
                    if ($session->has($sessionKey)) {
                        $result = $session->get($sessionKey);
                    } else {
                        $result = $this->performGeolocation($address);
                        $session->set($sessionKey, $result);
                    }
                    break;
                default:
                    $result->setError(GeolocationResult::ERR_IPNOTPUBLIC);
                    break;
            }
        } catch (Exception $x) {
            $result->setError(GeolocationResult::ERR_OTHER, '', $x);
        } catch (Throwable $x) {
            $result->setError(GeolocationResult::ERR_OTHER, '', new Exception($x->getMessage(), $x->getCode()));
        }

        return $result;
    }
99404
public function registerGeoIpService()
    {
        $this->app->singleton('geoip', function ($app) {
            return new GeoIP(
                $app->config->get('geoip', []),
                $app['cache']
            );
        });
    }
358421
public function getLocation()
    {
        if ($this->location === null) {
            $this->location = new GeoLocation($this->getLat(), $this->getLng());
        }

        return $this->location;
    }
191970
protected function _execute($address) {
		$this->_Geocoder = new Geocoder();
		try {
			$addresses = $this->_Geocoder->geocode($address);
		} catch (InconclusiveException $e) {
			return null;
		} catch (NotAccurateEnoughException $e) {
			return null;
		}

		if (!$addresses || $addresses->count() < 1) {
			return null;
		}
		$address = $addresses->first();
		return $address;
	}
574955
public function executeStrategy($input){
		switch ($input){
			case 'adressesRue':
				$this->strategy=new AdressesRue($this->config);
				break;
			case 'ruesQuartier':
				$this->strategy=new RuesQuartier($this->config);
				break;
			case 'ruesSousQuartier':
				$this->strategy=new RuesSousQuartier($this->config);
				break;
			case 'quartiersVille':
				$this->strategy=new QuartiersVille($this->config);
				break;
			case 'adressesArchitecte':
				$this->strategy=new AdressesArchitecte($this->config);
				break;
			case 'urlPhotosRue':
				$this->strategy=new UrlPhotosRue($this->config);
				break;
			case 'urlPhotosQuartier':
				$this->strategy=new UrlPhotosQuartier($this->config);
				break;
			case 'ruesVille':
				$this->strategy=new RuesVille($this->config);
				break;
			case 'adressesQuartier':
				$this->strategy=new AdressesQuartier($this->config);
				break;
			case 'urlPhotosAdresse':
				$this->strategy=new UrlPhotosAdresse($this->config);
				break;
			default:
				$this->strategy=new AdressesRue($this->config);
		}
		$this->strategy->execute();
	}
1249274
protected function _execute($address) {
		/** @var \Geo\Model\Table\GeocodedAddressesTable|null $GeocodedAddresses */
		$GeocodedAddresses = null;
		if ($this->getConfig('cache')) {
			$GeocodedAddresses = TableRegistry::get('Geo.GeocodedAddresses');
			/** @var \Geo\Model\Entity\GeocodedAddress $result */
			$result = $GeocodedAddresses->find()->where(['address' => $address])->first();
			if ($result) {
				/** @var \Geocoder\Model\Address|null $data */
				$data = $result->data;
				return $data ?: null;
			}
		}

		try {
			$addresses = $this->_Geocoder->geocode($address);
		} catch (InconclusiveException $e) {
			$addresses = null;
		} catch (NotAccurateEnoughException $e) {
			$addresses = null;
		}
		$result = null;
		if ($addresses && $addresses->count() > 0) {
			$result = $addresses->first();
		}

		if ($this->getConfig('cache')) {
			/** @var \Geo\Model\Entity\GeocodedAddress $addressEntity */
			$addressEntity = $GeocodedAddresses->newEntity([
				'address' => $address
			]);
			if ($result) {
				$formatter = new StringFormatter();
				$addressEntity->formatted_address = $formatter->format($result, '%S %n, %z %L');
				$addressEntity->lat = $result->getLatitude();
				$addressEntity->lng = $result->getLongitude();
				$addressEntity->country = $result->getCountry()->getCode();
				$addressEntity->data = $result;
			}

			if (!$GeocodedAddresses->save($addressEntity, ['atomic' => false])) {
				throw new RuntimeException('Could not store geocoding cache data');
			}
		}

		return $result;
	}
1362741
public function addMapping($destinationPattern, $controllerClass, $actionName)
    {
        $mapping = new Route\Mapping($destinationPattern, $controllerClass, $actionName);

        $this->reverseMapping[$controllerClass][$actionName] = $mapping;

        $destinationPieces = explode('/', $destinationPattern);

        $mappingNode = &$this->routeMapping;
        foreach($destinationPieces as $destinationPiece) {
            if ($this->isWildcard($destinationPiece)) {
                if (!isset($mappingNode['_wildcard'])) {
                    $mappingNode['_wildcard'] = null;
                }
                $mappingNode = &$mappingNode['_wildcard'];
            } else {
                if (!isset($mappingNode[$destinationPiece])) {
                    $mappingNode[$destinationPiece] = null;
                }
                $mappingNode = &$mappingNode[$destinationPiece];
            }
        }
        $mappingNode['_mapping'] = $mapping;

        return $mapping;
    }
1336025
public function lookUp(\Tx_Oelib_Interface_Geo $geoObject)
    {
        if ($geoObject->hasGeoError() || $geoObject->hasGeoCoordinates()) {
            return;
        }
        if (!$geoObject->hasGeoAddress()) {
            $geoObject->setGeoError();
            return;
        }

        if (!empty($this->coordinates)) {
            $geoObject->setGeoCoordinates($this->coordinates);
        } else {
            $geoObject->setGeoError();
        }
    }
856286
public function reverseGeocodeBulk($geolocations)
    {
        $headers = ['Content-Type' => 'application/json'];
        $body = ['geolocations' => $geolocations];

        $request = new Request('POST', '/postcodes', $headers, json_encode($body));

        return $this->httpTransport($request);
    }
105494
public void putGeoLocation(final GeoLocationRequest location) {
        putGeoAccuracy(location.getAccuracy());
        putGeoLatitude(location.getLatitude());
        putGeoLongitude(location.getLongitude());
        putGeoTimestamp(location.getTimestamp());
    }
201421
protected function createGeocoder()
    {
        if ($this->apiKey === null) {
            throw new Exception('API key must be set before geocoding.');
        }

        if ($this->geocoder === null) {
            $this->geocoder = new GoogleMaps(
                new CurlHttpAdapter,
                $this->lang,
                null,
                true,
                $this->apiKey
            );
        }

        return $this->geocoder;
    }
896894
public function setGeoLocations($geoLocations)
    {
        $locationParts = explode(', ', $geoLocations);
        if (count($locationParts) < 2) {
            throw new Exception\GoogleNewsUrlException(
                sprintf(
                    'The parameter %s must be a valid geo_location. See https://support.google.com/news/publisher/answer/1662970?hl=en',
                    $geoLocations
                )
            );
        }
        $this->geoLocations = $geoLocations;

        return $this;
    }
1118140
public function analyzeMap(): void
    {
        $this->analyzeDuplicates('source', $this->sourceLanguage, $this->sourceMap, $this->sourceMapInverse);
        $this->analyzeDuplicates('target', $this->targetLanguage, $this->targetMap, $this->targetMapInverse);

        foreach ($this->targetMap as $targetId => $mainId) {
            if (!array_key_exists($mainId, $this->sourceMapInverse)) {
                $this->logger->warning(
                    'No source for target found. ' .
                    '{targetLanguage}: {targetId} => {mainLanguage}: {mainId} <= {sourceLanguage}: ?',
                    [
                        'sourceLanguage' => $this->sourceLanguage,
                        'mainLanguage'   => $this->mainLanguage,
                        'targetLanguage' => $this->targetLanguage,
                        'targetId'       => $targetId,
                        'mainId'         => $mainId,
                        'msg_type'       => 'no_source_for_target',
                        'class'          => \get_class($this),
                    ]
                );
            }
        }
    }
617454
function createGeo() {
    $cnt = count( $this->geo );
    if( 0 >= $cnt )
      return;
    $attributes = $this->_createParams( $this->geo['params'] );
    $content    = null;
    $content   .= number_format( (float) $this->geo['value']['latitude'], 6, '.', '');
    $content   .= ';';
    $content   .= number_format( (float) $this->geo['value']['longitude'], 6, '.', '');
    return $this->_createElement( 'GEO', $attributes, $content );
  }