@@ -119,23 +119,29 @@ public function geocodeQuery(GeocodeQuery $query): Collection
119119
120120 $ results = [];
121121 foreach ($ json ->ValidateAddressesResponse ->ValidatedAddressResultList ->ValidatedAddressResult as $ location ) {
122- $ coordinates = $ location ->ValidatedAddressList ->ValidatedAddress [0 ]->ServicePointDetail ->GeographicalLocationInfo ->GeographicalLocation ;
123- $ streetName = !empty ($ location ->ValidatedAddressList ->ValidatedAddress [0 ]->PostalAddress ->StructuredDeliveryPointLocation ->StreetName ) ? $ location ->ValidatedAddressList ->ValidatedAddress [0 ]->PostalAddress ->StructuredDeliveryPointLocation ->StreetName : null ;
124- $ number = !empty ($ location ->ValidatedAddressList ->ValidatedAddress [0 ]->PostalAddress ->StructuredDeliveryPointLocation ->StreetNumber ) ? $ location ->ValidatedAddressList ->ValidatedAddress [0 ]->PostalAddress ->StructuredDeliveryPointLocation ->StreetNumber : null ;
125- $ municipality = !empty ($ location ->ValidatedAddressList ->ValidatedAddress [0 ]->PostalAddress ->StructuredPostalCodeMunicipality ->MunicipalityName ) ? $ location ->ValidatedAddressList ->ValidatedAddress [0 ]->PostalAddress ->StructuredPostalCodeMunicipality ->MunicipalityName : null ;
126- $ postCode = !empty ($ location ->ValidatedAddressList ->ValidatedAddress [0 ]->PostalAddress ->StructuredPostalCodeMunicipality ->PostalCode ) ? $ location ->ValidatedAddressList ->ValidatedAddress [0 ]->PostalAddress ->StructuredPostalCodeMunicipality ->PostalCode : null ;
127- $ countryCode = 'BE ' ;
128-
129- $ results [] = Address::createFromArray ([
130- 'providedBy ' => $ this ->getName (),
131- 'latitude ' => $ coordinates ->Latitude ->Value ,
132- 'longitude ' => $ coordinates ->Longitude ->Value ,
133- 'streetNumber ' => $ number ,
134- 'streetName ' => $ streetName ,
135- 'locality ' => $ municipality ,
136- 'postalCode ' => $ postCode ,
137- 'countryCode ' => $ countryCode ,
138- ]);
122+ if (isset ($ location ->ValidatedAddressList ->ValidatedAddress [0 ]->ServicePointDetail , $ location ->ValidatedAddressList ->ValidatedAddress [0 ]->PostalAddress )) {
123+ $ coordinates = $ location ->ValidatedAddressList ->ValidatedAddress [0 ]->ServicePointDetail ->GeographicalLocationInfo ->GeographicalLocation ;
124+
125+ $ postalAddress = $ location ->ValidatedAddressList ->ValidatedAddress [0 ]->PostalAddress ;
126+
127+ $ streetName = !empty ($ postalAddress ->StructuredDeliveryPointLocation ->StreetName ) ? $ postalAddress ->StructuredDeliveryPointLocation ->StreetName : null ;
128+ $ number = !empty ($ postalAddress ->StructuredDeliveryPointLocation ->StreetNumber ) ? $ postalAddress ->StructuredDeliveryPointLocation ->StreetNumber : null ;
129+ $ municipality = !empty ($ postalAddress ->StructuredPostalCodeMunicipality ->MunicipalityName ) ? $ postalAddress ->StructuredPostalCodeMunicipality ->MunicipalityName : null ;
130+ $ postCode = !empty ($ postalAddress ->StructuredPostalCodeMunicipality ->PostalCode ) ? $ postalAddress ->StructuredPostalCodeMunicipality ->PostalCode : null ;
131+ $ countryCode = 'BE ' ;
132+
133+ $ results [] = Address::createFromArray ([
134+ 'providedBy ' => $ this ->getName (),
135+ 'latitude ' => $ coordinates ->Latitude ->Value ,
136+ 'longitude ' => $ coordinates ->Longitude ->Value ,
137+ 'streetNumber ' => $ number ,
138+ 'streetName ' => $ streetName ,
139+ 'locality ' => $ municipality ,
140+ 'postalCode ' => $ postCode ,
141+ 'countryCode ' => $ countryCode ,
142+ ]);
143+
144+ }
139145 }
140146
141147 return new AddressCollection ($ results );
0 commit comments