- private function fillAddressWithGeocoding(Address &$address, $geocodedData, $isLocal) {
- // The geocoded address three is
- // Country -> AdministrativeArea -> SubAdministrativeArea -> Locality -> Thoroughfare
- // with all the possible shortcuts
- // The address is formatted as xAL, or eXtensible Address Language, an international
- // standard for address formatting.
- // xAL documentation: http://www.oasis-open.org/committees/ciq/ciq.html#6
- if ($isLocal) {
- $ext = 'Local';
- } else {
- $ext = ucfirst(Platal::globals()->geocoder->gmaps_hl);
- $address->geocodedText = str_replace(', ', "\n", $geocodedData['address']);
- }
-
- if (isset($geocodedData['AddressDetails']['Accuracy'])) {
- $address->accuracy = $geocodedData['AddressDetails']['Accuracy'];
- }
-
- $currentPosition = $geocodedData['AddressDetails'];
- if (isset($currentPosition['Country'])) {
- $country = 'country' . $ext;
- $currentPosition = $currentPosition['Country'];
- $address->countryId = $currentPosition['CountryNameCode'];
- $address->$country = $currentPosition['CountryName'];
- }
- if (isset($currentPosition['AdministrativeArea'])) {
- $administrativeAreaName = 'administrativeAreaName' . $ext;
- $currentPosition = $currentPosition['AdministrativeArea'];
- $address->$administrativeAreaName = $currentPosition['AdministrativeAreaName'];
- }
- if (isset($currentPosition['SubAdministrativeArea'])) {
- $subAdministrativeAreaName = 'subAdministrativeAreaName' . $ext;
- $currentPosition = $currentPosition['SubAdministrativeArea'];
- $address->$subAdministrativeAreaName = $currentPosition['SubAdministrativeAreaName'];
- }
- if (isset($currentPosition['Locality'])) {
- $localityName = 'localityName' . $ext;
- $currentPosition = $currentPosition['Locality'];
- $address->$localityName = $currentPosition['LocalityName'];
- }
- if (isset($currentPosition['PostalCode'])) {
- $address->postalCode = $currentPosition['PostalCode']['PostalCodeNumber'];
- }
-
- // Gets coordinates.
- if (isset($geocodedData['Point']['coordinates'][0])) {
- $address->latitude = $geocodedData['Point']['coordinates'][0];
- }
- if (isset($geocodedData['Point']['coordinates'][1])) {
- $address->longitude = $geocodedData['Point']['coordinates'][1];
- }
- if (isset($geocodedData['ExtendedData']['LatLonBox']['north'])) {
- $address->north = $geocodedData['ExtendedData']['LatLonBox']['north'];
- }
- if (isset($geocodedData['ExtendedData']['LatLonBox']['south'])) {
- $address->south = $geocodedData['ExtendedData']['LatLonBox']['south'];
- }
- if (isset($geocodedData['ExtendedData']['LatLonBox']['east'])) {
- $address->east = $geocodedData['ExtendedData']['LatLonBox']['east'];
- }
- if (isset($geocodedData['ExtendedData']['LatLonBox']['west'])) {
- $address->west = $geocodedData['ExtendedData']['LatLonBox']['west'];
- }
- }
-
- // Compares the geocoded address with the given address and returns true
- // iff their are close enough to be considered as equals or not.
- private function compareAddress($address)
- {
- $same = true;
- $geoloc = strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"),
- array('', "\n"), $address->geocodedText));
- $text = strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"),
- array('', "\n"), $address->text));
- $arrayGeoloc = explode("\n", $geoloc);
- $arrayText = explode("\n", $text);
- $countGeoloc = count($arrayGeoloc);
- $countText = count($arrayText);
-
- $totalDistance = 0;
- if (($countText > $countGeoloc) || ($countText < $countGeoloc - 1)
- || (($countText == $countGeoloc - 1)
- && ($arrayText[$countText - 1] == strtoupper($address->country)))) {
- $same = false;
- } else {
- for ($i = 0; $i < $countGeoloc && $i < $countText; ++$i) {
- $lineDistance = levenshtein($arrayText[$i], trim($arrayGeoloc[$i]));
- $totalDistance += $lineDistance;
- if ($lineDistance > self::MAX_LINE_DISTANCE || $totalDistance > self::MAX_TOTAL_DISTANCE) {
- $same = false;
- break;
- }
- }
- }
-
- return $same;
+ private function fillAddressWithGeocoding(Address $address, $geocodedData, $isLocal) {
+ $address->types = implode(',', $geocodedData['types']);
+ $address->formatted_address = $geocodedData['formatted_address'];
+ $address->components = $geocodedData['address_components'];
+ $address->latitude = $geocodedData['geometry']['location']['lat'];
+ $address->longitude = $geocodedData['geometry']['location']['lng'];
+ $address->southwest_latitude = $geocodedData['geometry']['viewport']['southwest']['lat'];
+ $address->southwest_longitude = $geocodedData['geometry']['viewport']['southwest']['lng'];
+ $address->northeast_latitude = $geocodedData['geometry']['viewport']['northeast']['lat'];
+ $address->northeast_longitude = $geocodedData['geometry']['viewport']['northeast']['lng'];
+ $address->location_type = $geocodedData['geometry']['location_type'];
+ $address->partial_match = isset($geocodedData['partial_match']) ? true : false;