* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
// Maximum levenshtein distance authorized between input and geocoded text in the whole text.
const MAX_TOTAL_DISTANCE = 6;
// Maximum levenshtein distance authorized between input and geocoded text in the whole text.
const MAX_TOTAL_DISTANCE = 6;
- if (($geocodedData = $this->getPlacemarkForAddress($textAddress))) {
- $this->getUpdatedAddress($address, $geocodedData, null);
+ if (($geocodedData = $this->getPlacemarkForAddress($textAddress, $defaultLanguage))) {
+ $this->getUpdatedAddress($address, $geocodedData, null, $forceLanguage);
for ($i = max(1, $linesCount - self::MAX_GMAPS_RPC_CALLS + 1); $i < $linesCount; ++$i) {
$extraLines = implode("\n", array_slice($addressLines, 0, $i));
$toGeocode = implode("\n", array_slice($addressLines, $i));
for ($i = max(1, $linesCount - self::MAX_GMAPS_RPC_CALLS + 1); $i < $linesCount; ++$i) {
$extraLines = implode("\n", array_slice($addressLines, 0, $i));
$toGeocode = implode("\n", array_slice($addressLines, $i));
- if (($geocodedData = $this->getPlacemarkForAddress($toGeocode))) {
- $this->getUpdatedAddress($address, $geocodedData, $extraLines);
+ if (($geocodedData = $this->getPlacemarkForAddress($toGeocode, $defaultLanguage))) {
+ $this->getUpdatedAddress($address, $geocodedData, $extraLines, $forceLanguage);
$address->geocodedText = null;
$address->geoloc_choice = null;
$address->countryId = null;
$address->geocodedText = null;
$address->geoloc_choice = null;
$address->countryId = null;
// Updates the address with the geocoded information from Google Maps. Also
// cleans up the final informations.
// Updates the address with the geocoded information from Google Maps. Also
// cleans up the final informations.
- private function getUpdatedAddress(Address &$address, array $geocodedData, $extraLines) {
+ private function getUpdatedAddress(Address $address, array $geocodedData, $extraLines, $forceLanguage) {
}
// Retrieves the Placemark object (see #getPlacemarkFromJson()) for the @p
// address, by querying the Google Maps API. Returns the array on success,
// and null otherwise.
}
// Retrieves the Placemark object (see #getPlacemarkFromJson()) for the @p
// address, by querying the Google Maps API. Returns the array on success,
// and null otherwise.
- private function getPlacemarkForAddress($address, $defaultLanguage = null) {
- if (is_null($defaultLanguage)) {
- $defaultLanguage = Platal::globals()->geocoder->gmaps_hl;
- }
-
+ private function getPlacemarkForAddress($address, $defaultLanguage) {
$url = $this->getGeocodingUrl($address, $defaultLanguage);
$geoData = $this->getGeoJsonFromUrl($url);
$url = $this->getGeocodingUrl($address, $defaultLanguage);
$geoData = $this->getGeoJsonFromUrl($url);
// The geocoded address three is
// Country -> AdministrativeArea -> SubAdministrativeArea -> Locality -> Thoroughfare
// with all the possible shortcuts
// The geocoded address three is
// Country -> AdministrativeArea -> SubAdministrativeArea -> Locality -> Thoroughfare
// with all the possible shortcuts
// Formats the text of the geocoded address using the unused data and
// compares it to the given address. If they are too different, the user
// will be asked to choose between them.
// Formats the text of the geocoded address using the unused data and
// compares it to the given address. If they are too different, the user
// will be asked to choose between them.
- } else {
- $languages = XDB::fetchOneCell('SELECT IF(ISNULL(gc1.belongsTo), gc1.languages, gc2.languages)
+ } elseif (!$forceLanguage) {
+ $languages = XDB::fetchOneCell('SELECT IF(ISNULL(gc1.belongsTo), gl1.language, gl2.language)
WHERE gc1.iso_3166_1_a2 = {?}',
$address->countryId);
$toGeocode = substr($address->text, strlen($extraLines));
WHERE gc1.iso_3166_1_a2 = {?}',
$address->countryId);
$toGeocode = substr($address->text, strlen($extraLines));