Skip to content

Commit

Permalink
Update Addok.php
Browse files Browse the repository at this point in the history
Get correct properties when `type=street` instead of `type=housenumber`
  • Loading branch information
jbelien committed Feb 12, 2018
1 parent 9b03a25 commit 6fe7a2b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Addok.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,28 @@ public function geocodeQuery(GeocodeQuery $query): Collection
$results = [];
foreach ($json->features as $feature) {
$coordinates = $feature->geometry->coordinates;
$streetName = !empty($feature->properties->street) ? $feature->properties->street : null;
$number = !empty($feature->properties->housenumber) ? $feature->properties->housenumber : null;
$municipality = !empty($feature->properties->city) ? $feature->properties->city : null;
$postCode = !empty($feature->properties->postCode) ? $feature->properties->postCode : null;

switch ($feature->properties->type) {
case 'housenumber':
$streetName = !empty($feature->properties->street) ? $feature->properties->street : null;
$number = !empty($feature->properties->housenumber) ? $feature->properties->housenumber : null;
break;
case 'street':
$streetName = !empty($feature->properties->name) ? $feature->properties->name : null;
$number = null;
break;
}
$locality = !empty($feature->properties->city) ? $feature->properties->city : null;
$postalCode = !empty($feature->properties->postcode) ? $feature->properties->postcode : null;

$results[] = Address::createFromArray([
'providedBy' => $this->getName(),
'latitude' => $coordinates[1],
'longitude' => $coordinates[0],
'streetNumber' => $number,
'streetName' => $streetName,
'locality' => $municipality,
'postalCode' => $postCode,
'locality' => $locality,
'postalCode' => $postalCode,
]);
}

Expand Down

0 comments on commit 6fe7a2b

Please sign in to comment.