|
17 | 17 | use Geocoder\Exception\InvalidServerResponse;
|
18 | 18 | use Geocoder\Exception\QuotaExceeded;
|
19 | 19 | use Geocoder\Exception\UnsupportedOperation;
|
20 |
| -use Geocoder\Model\AddressCollection; |
21 |
| -use Geocoder\Model\AddressBuilder; |
22 |
| -use Geocoder\Query\GeocodeQuery; |
23 |
| -use Geocoder\Query\ReverseQuery; |
24 | 20 | use Geocoder\Http\Provider\AbstractHttpProvider;
|
| 21 | +use Geocoder\Model\AddressBuilder; |
| 22 | +use Geocoder\Model\AddressCollection; |
25 | 23 | use Geocoder\Provider\GoogleMaps\Model\GoogleAddress;
|
26 | 24 | use Geocoder\Provider\Provider;
|
| 25 | +use Geocoder\Query\GeocodeQuery; |
| 26 | +use Geocoder\Query\ReverseQuery; |
27 | 27 | use Http\Client\HttpClient;
|
28 | 28 |
|
29 | 29 | /**
|
@@ -79,8 +79,14 @@ final class GoogleMaps extends AbstractHttpProvider implements Provider
|
79 | 79 | *
|
80 | 80 | * @return GoogleMaps
|
81 | 81 | */
|
82 |
| - public static function business(HttpClient $client, string $clientId, string $privateKey = null, string $region = null, string $apiKey = null, string $channel = null) |
83 |
| - { |
| 82 | + public static function business( |
| 83 | + HttpClient $client, |
| 84 | + string $clientId, |
| 85 | + string $privateKey = null, |
| 86 | + string $region = null, |
| 87 | + string $apiKey = null, |
| 88 | + string $channel = null |
| 89 | + ) { |
84 | 90 | $provider = new self($client, $region, $apiKey);
|
85 | 91 | $provider->clientId = $clientId;
|
86 | 92 | $provider->privateKey = $privateKey;
|
@@ -112,7 +118,13 @@ public function geocodeQuery(GeocodeQuery $query): Collection
|
112 | 118 |
|
113 | 119 | $url = sprintf(self::GEOCODE_ENDPOINT_URL_SSL, rawurlencode($query->getText()));
|
114 | 120 | if (null !== $bounds = $query->getBounds()) {
|
115 |
| - $url .= sprintf('&bounds=%s,%s|%s,%s', $bounds->getSouth(), $bounds->getWest(), $bounds->getNorth(), $bounds->getEast()); |
| 121 | + $url .= sprintf( |
| 122 | + '&bounds=%s,%s|%s,%s', |
| 123 | + $bounds->getSouth(), |
| 124 | + $bounds->getWest(), |
| 125 | + $bounds->getNorth(), |
| 126 | + $bounds->getEast() |
| 127 | + ); |
116 | 128 | }
|
117 | 129 |
|
118 | 130 | if (null !== $components = $query->getData('components')) {
|
@@ -233,22 +245,24 @@ private function fetchUrl(string $url, string $locale = null, int $limit, string
|
233 | 245 | if (isset($result->formatted_address)) {
|
234 | 246 | $address = $address->withFormattedAddress($result->formatted_address);
|
235 | 247 | }
|
236 |
| - $address = $address->withStreetAddress($builder->getValue('street_address')); |
237 |
| - $address = $address->withIntersection($builder->getValue('intersection')); |
238 |
| - $address = $address->withPolitical($builder->getValue('political')); |
239 |
| - $address = $address->withColloquialArea($builder->getValue('colloquial_area')); |
240 |
| - $address = $address->withWard($builder->getValue('ward')); |
241 |
| - $address = $address->withNeighborhood($builder->getValue('neighborhood')); |
242 |
| - $address = $address->withPremise($builder->getValue('premise')); |
243 |
| - $address = $address->withSubpremise($builder->getValue('subpremise')); |
244 |
| - $address = $address->withNaturalFeature($builder->getValue('natural_feature')); |
245 |
| - $address = $address->withAirport($builder->getValue('airport')); |
246 |
| - $address = $address->withPark($builder->getValue('park')); |
247 |
| - $address = $address->withPointOfInterest($builder->getValue('point_of_interest')); |
248 |
| - $address = $address->withEstablishment($builder->getValue('establishment')); |
249 |
| - $address = $address->withSubLocalityLevels($builder->getValue('subLocalityLevel', [])); |
250 |
| - $address = $address->withPartialMatch($result->partial_match ?? false); |
251 |
| - $results[] = $address; |
| 248 | + |
| 249 | + $results[] = $address |
| 250 | + ->withStreetAddress($builder->getValue('street_address')) |
| 251 | + ->withIntersection($builder->getValue('intersection')) |
| 252 | + ->withPolitical($builder->getValue('political')) |
| 253 | + ->withColloquialArea($builder->getValue('colloquial_area')) |
| 254 | + ->withWard($builder->getValue('ward')) |
| 255 | + ->withNeighborhood($builder->getValue('neighborhood')) |
| 256 | + ->withPremise($builder->getValue('premise')) |
| 257 | + ->withSubpremise($builder->getValue('subpremise')) |
| 258 | + ->withNaturalFeature($builder->getValue('natural_feature')) |
| 259 | + ->withAirport($builder->getValue('airport')) |
| 260 | + ->withPark($builder->getValue('park')) |
| 261 | + ->withPointOfInterest($builder->getValue('point_of_interest')) |
| 262 | + ->withEstablishment($builder->getValue('establishment')) |
| 263 | + ->withSubLocalityLevels($builder->getValue('subLocalityLevel', [])) |
| 264 | + ->withPostalCodeSuffix($builder->getValue('postal_code_suffix')) |
| 265 | + ->withPartialMatch($result->partial_match ?? false); |
252 | 266 |
|
253 | 267 | if (count($results) >= $limit) {
|
254 | 268 | break;
|
@@ -337,6 +351,7 @@ private function updateAddressComponent(AddressBuilder $builder, string $type, $
|
337 | 351 | case 'park':
|
338 | 352 | case 'point_of_interest':
|
339 | 353 | case 'establishment':
|
| 354 | + case 'postal_code_suffix': |
340 | 355 | $builder->setValue($type, $values->long_name);
|
341 | 356 |
|
342 | 357 | break;
|
@@ -392,7 +407,7 @@ private function serializeComponents(array $components): string
|
392 | 407 | * @param string $url
|
393 | 408 | * @param string $content
|
394 | 409 | *
|
395 |
| - * @return mixed result form json_decode() |
| 410 | + * @return \Stdclass result form json_decode() |
396 | 411 | *
|
397 | 412 | * @throws InvalidCredentials
|
398 | 413 | * @throws InvalidServerResponse
|
@@ -431,10 +446,10 @@ private function validateResponse(string $url, $content)
|
431 | 446 | }
|
432 | 447 |
|
433 | 448 | /**
|
434 |
| - * Parse coordinats and bounds. |
| 449 | + * Parse coordinates and bounds. |
435 | 450 | *
|
436 | 451 | * @param AddressBuilder $builder
|
437 |
| - * @param $result |
| 452 | + * @param \Stdclass $result |
438 | 453 | */
|
439 | 454 | private function parseCoordinates(AddressBuilder $builder, $result)
|
440 | 455 | {
|
|
0 commit comments