diff --git a/README.md b/README.md index 0ad4e240b..16a43c4c3 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ objects (`AddressCollection`), each providing the following API: properties); * `getCountryCode()` will return the ISO `country` code; * `getTimezone()` will return the `timezone`. +* `getFormattedAddress()` will return the `formattedAddress`. The `AddressCollection` exposes the following methods: diff --git a/src/Geocoder/Model/Address.php b/src/Geocoder/Model/Address.php index 8eaf4cd47..34c749b2b 100644 --- a/src/Geocoder/Model/Address.php +++ b/src/Geocoder/Model/Address.php @@ -65,6 +65,11 @@ final class Address */ private $timezone; + /** + * @var string + */ + private $formattedAddress; + /** * @param string $streetNumber * @param string $streetName @@ -82,18 +87,20 @@ public function __construct( $subLocality = null, AdminLevelCollection $adminLevels = null, Country $country = null, - $timezone = null + $timezone = null, + $formattedAddress = null ) { - $this->coordinates = $coordinates; - $this->bounds = $bounds; - $this->streetNumber = $streetNumber; - $this->streetName = $streetName; - $this->postalCode = $postalCode; - $this->locality = $locality; - $this->subLocality = $subLocality; - $this->adminLevels = $adminLevels ?: new AdminLevelCollection(); - $this->country = $country; - $this->timezone = $timezone; + $this->coordinates = $coordinates; + $this->bounds = $bounds; + $this->streetNumber = $streetNumber; + $this->streetName = $streetName; + $this->postalCode = $postalCode; + $this->locality = $locality; + $this->subLocality = $subLocality; + $this->adminLevels = $adminLevels ?: new AdminLevelCollection(); + $this->country = $country; + $this->timezone = $timezone; + $this->formattedAddress = $formattedAddress; } /** @@ -235,6 +242,16 @@ public function getTimezone() return $this->timezone; } + /** + * Returns the formatted address. + * + * @return string + */ + public function getFormattedAddress() + { + return $this->formattedAddress; + } + /** * Returns an array with data indexed by name. * @@ -251,18 +268,19 @@ public function toArray() } return array( - 'latitude' => $this->getLatitude(), - 'longitude' => $this->getLongitude(), - 'bounds' => $this->bounds->toArray(), - 'streetNumber' => $this->streetNumber, - 'streetName' => $this->streetName, - 'postalCode' => $this->postalCode, - 'locality' => $this->locality, - 'subLocality' => $this->subLocality, - 'adminLevels' => $adminLevels, - 'country' => $this->country->getName(), - 'countryCode' => $this->country->getCode(), - 'timezone' => $this->timezone, + 'latitude' => $this->getLatitude(), + 'longitude' => $this->getLongitude(), + 'bounds' => $this->bounds->toArray(), + 'streetNumber' => $this->streetNumber, + 'streetName' => $this->streetName, + 'postalCode' => $this->postalCode, + 'locality' => $this->locality, + 'subLocality' => $this->subLocality, + 'adminLevels' => $adminLevels, + 'country' => $this->country->getName(), + 'countryCode' => $this->country->getCode(), + 'timezone' => $this->timezone, + 'formattedAddress' => $this->formattedAddress, ); } } diff --git a/src/Geocoder/Model/AddressFactory.php b/src/Geocoder/Model/AddressFactory.php index 2d28b295f..8260e3545 100644 --- a/src/Geocoder/Model/AddressFactory.php +++ b/src/Geocoder/Model/AddressFactory.php @@ -54,7 +54,8 @@ public function createFromArray(array $results) $this->readStringValue($result, 'country'), $this->upperize(\igorw\get_in($result, ['countryCode'])) ), - \igorw\get_in($result, ['timezone']) + \igorw\get_in($result, ['timezone']), + $this->readStringValue($result, 'formattedAddress') ); } diff --git a/src/Geocoder/Provider/AbstractProvider.php b/src/Geocoder/Provider/AbstractProvider.php index ea4050fcd..08ab48b9b 100644 --- a/src/Geocoder/Provider/AbstractProvider.php +++ b/src/Geocoder/Provider/AbstractProvider.php @@ -60,23 +60,24 @@ public function getLimit() protected function getDefaults() { return [ - 'latitude' => null, - 'longitude' => null, - 'bounds' => [ + 'latitude' => null, + 'longitude' => null, + 'bounds' => [ 'south' => null, 'west' => null, 'north' => null, 'east' => null, ], - 'streetNumber' => null, - 'streetName' => null, - 'locality' => null, - 'postalCode' => null, - 'subLocality' => null, - 'adminLevels' => [], - 'country' => null, - 'countryCode' => null, - 'timezone' => null, + 'streetNumber' => null, + 'streetName' => null, + 'locality' => null, + 'postalCode' => null, + 'subLocality' => null, + 'adminLevels' => [], + 'country' => null, + 'countryCode' => null, + 'timezone' => null, + 'formattedAddress' => null, ]; } diff --git a/src/Geocoder/Provider/GoogleMaps.php b/src/Geocoder/Provider/GoogleMaps.php index 977dea858..2b5b6786d 100644 --- a/src/Geocoder/Provider/GoogleMaps.php +++ b/src/Geocoder/Provider/GoogleMaps.php @@ -208,6 +208,8 @@ private function executeQuery($query) ); } + $resultSet['formattedAddress'] = $result->formatted_address; + $results[] = array_merge($this->getDefaults(), $resultSet); }