Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
64 changes: 41 additions & 23 deletions src/Geocoder/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ final class Address
*/
private $timezone;

/**
* @var string
*/
private $formattedAddress;

/**
* @param string $streetNumber
* @param string $streetName
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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.
*
Expand All @@ -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,
);
}
}
3 changes: 2 additions & 1 deletion src/Geocoder/Model/AddressFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
}

Expand Down
25 changes: 13 additions & 12 deletions src/Geocoder/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand Down
2 changes: 2 additions & 0 deletions src/Geocoder/Provider/GoogleMaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ private function executeQuery($query)
);
}

$resultSet['formattedAddress'] = $result->formatted_address;

$results[] = array_merge($this->getDefaults(), $resultSet);
}

Expand Down