@@ -157,6 +157,7 @@ public static function createUsingApiKey(ClientInterface $client, string $apiKey
157157
158158 public function geocodeQuery (GeocodeQuery $ query ): Collection
159159 {
160+
160161 // This API doesn't handle IPs
161162 if (filter_var ($ query ->getText (), FILTER_VALIDATE_IP )) {
162163 throw new UnsupportedOperation ('The Here provider does not support IP addresses, only street addresses. ' );
@@ -202,18 +203,30 @@ private function geocodeQueryGS7(GeocodeQuery $query): Collection
202203 'limit ' => $ query ->getLimit (),
203204 ]);
204205
206+ // Pass-through for GS7 geo filters / sorting reference point.
207+ // See https://www.here.com/docs/bundle/geocoding-and-search-api-v7-api-reference/page/index.html#/paths/~1geocode/get
208+ if (null !== $ at = $ query ->getData ('at ' )) {
209+ $ queryParams ['at ' ] = $ at ;
210+ }
211+ if (null !== $ in = $ query ->getData ('in ' )) {
212+ $ queryParams ['in ' ] = $ in ;
213+ }
214+ if (null !== $ types = $ query ->getData ('types ' )) {
215+ $ queryParams ['types ' ] = $ types ;
216+ }
217+
205218 $ qq = [];
206219 if (null !== $ country = $ query ->getData ('country ' )) {
207- $ qq [] = 'country= ' . $ country ;
220+ $ qq [] = 'country= ' . $ country ;
208221 }
209222 if (null !== $ state = $ query ->getData ('state ' )) {
210- $ qq [] = 'state= ' . $ state ;
223+ $ qq [] = 'state= ' . $ state ;
211224 }
212225 if (null !== $ county = $ query ->getData ('county ' )) {
213- $ qq [] = 'county= ' . $ county ;
226+ $ qq [] = 'county= ' . $ county ;
214227 }
215228 if (null !== $ city = $ query ->getData ('city ' )) {
216- $ qq [] = 'city= ' . $ city ;
229+ $ qq [] = 'city= ' . $ city ;
217230 }
218231
219232 if (!empty ($ qq )) {
@@ -303,6 +316,7 @@ private function executeQuery(string $url, int $limit): Collection
303316
304317 private function parseGS7Response (array $ items , int $ limit ): Collection
305318 {
319+
306320 $ results = [];
307321
308322 foreach ($ items as $ item ) {
@@ -321,7 +335,9 @@ private function parseGS7Response(array $items, int $limit): Collection
321335 $ builder ->setStreetName ($ address ['street ' ] ?? null );
322336 $ builder ->setPostalCode ($ address ['postalCode ' ] ?? null );
323337 $ builder ->setLocality ($ address ['city ' ] ?? null );
324- $ builder ->setSubLocality ($ address ['district ' ] ?? null );
338+ // GS7 may provide both `district` and `subdistrict`. Prefer `district` for backward compatibility,
339+ // but fall back to `subdistrict` when `district` is missing.
340+ $ builder ->setSubLocality ($ address ['district ' ] ?? ($ address ['subdistrict ' ] ?? null ));
325341 $ builder ->setCountryCode ($ address ['countryCode ' ] ?? null );
326342 $ builder ->setCountry ($ address ['countryName ' ] ?? null );
327343
@@ -332,15 +348,61 @@ private function parseGS7Response(array $items, int $limit): Collection
332348 $ hereAddress = $ hereAddress ->withLocationName ($ item ['title ' ] ?? null );
333349
334350 $ additionalData = [];
351+ if (isset ($ address ['label ' ])) {
352+ $ additionalData [] = ['key ' => 'Label ' , 'value ' => $ address ['label ' ]];
353+ }
335354 if (isset ($ address ['countryName ' ])) {
336355 $ additionalData [] = ['key ' => 'CountryName ' , 'value ' => $ address ['countryName ' ]];
337356 }
338357 if (isset ($ address ['state ' ])) {
339358 $ additionalData [] = ['key ' => 'StateName ' , 'value ' => $ address ['state ' ]];
340359 }
360+ if (isset ($ address ['stateCode ' ])) {
361+ $ additionalData [] = ['key ' => 'StateCode ' , 'value ' => $ address ['stateCode ' ]];
362+ }
341363 if (isset ($ address ['county ' ])) {
342364 $ additionalData [] = ['key ' => 'CountyName ' , 'value ' => $ address ['county ' ]];
343365 }
366+ if (isset ($ address ['countyCode ' ])) {
367+ $ additionalData [] = ['key ' => 'CountyCode ' , 'value ' => $ address ['countyCode ' ]];
368+ }
369+ if (isset ($ address ['district ' ])) {
370+ $ additionalData [] = ['key ' => 'District ' , 'value ' => $ address ['district ' ]];
371+ }
372+ if (isset ($ address ['subdistrict ' ])) {
373+ $ additionalData [] = ['key ' => 'Subdistrict ' , 'value ' => $ address ['subdistrict ' ]];
374+ }
375+ if (isset ($ address ['streets ' ])) {
376+ $ additionalData [] = ['key ' => 'Streets ' , 'value ' => $ address ['streets ' ]];
377+ }
378+ if (isset ($ address ['block ' ])) {
379+ $ additionalData [] = ['key ' => 'Block ' , 'value ' => $ address ['block ' ]];
380+ }
381+ if (isset ($ address ['subblock ' ])) {
382+ $ additionalData [] = ['key ' => 'Subblock ' , 'value ' => $ address ['subblock ' ]];
383+ }
384+ if (isset ($ address ['building ' ])) {
385+ $ additionalData [] = ['key ' => 'Building ' , 'value ' => $ address ['building ' ]];
386+ }
387+ if (isset ($ address ['unit ' ])) {
388+ $ additionalData [] = ['key ' => 'Unit ' , 'value ' => $ address ['unit ' ]];
389+ }
390+
391+ // Item metadata
392+ foreach (
393+ [
394+ 'politicalView ' => 'PoliticalView ' ,
395+ 'houseNumberType ' => 'HouseNumberType ' ,
396+ 'addressBlockType ' => 'AddressBlockType ' ,
397+ 'localityType ' => 'LocalityType ' ,
398+ 'administrativeAreaType ' => 'AdministrativeAreaType ' ,
399+ 'distance ' => 'Distance ' ,
400+ ] as $ sourceKey => $ targetKey
401+ ) {
402+ if (isset ($ item [$ sourceKey ])) {
403+ $ additionalData [] = ['key ' => $ targetKey , 'value ' => $ item [$ sourceKey ]];
404+ }
405+ }
344406
345407 $ hereAddress = $ hereAddress ->withAdditionalData ($ additionalData );
346408 $ results [] = $ hereAddress ;
0 commit comments