Skip to content

Commit

Permalink
Update Geopunt.php
Browse files Browse the repository at this point in the history
Use AddressBuilder.
Fix bounds.
  • Loading branch information
jbelien committed Jul 2, 2018
1 parent bff454e commit 0be13b4
Showing 1 changed file with 31 additions and 42 deletions.
73 changes: 31 additions & 42 deletions Geopunt.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Geocoder\Exception\UnsupportedOperation;
use Geocoder\Http\Provider\AbstractHttpProvider;
use Geocoder\Model\Address;
use Geocoder\Model\AddressBuilder;
use Geocoder\Model\AddressCollection;
use Geocoder\Provider\Provider;
use Geocoder\Query\GeocodeQuery;
Expand Down Expand Up @@ -73,31 +74,25 @@ public function geocodeQuery(GeocodeQuery $query): Collection

$results = [];
foreach ($json->LocationResult as $location) {
$coordinates = $location->Location;
$streetName = !empty($location->Thoroughfarename) ? $location->Thoroughfarename : null;
$housenumber = !empty($location->Housenumber) ? $location->Housenumber : null;
$municipality = !empty($location->Municipality) ? $location->Municipality : null;
$zipcode = !empty($location->Zipcode) ? $location->Zipcode : null;
$countryCode = 'BE';

$bounds = [
'west' => $location->BoundingBox->LowerLeft->Lon_WGS84,
'south' => $location->BoundingBox->UpperRight->Lat_WGS84,
'east' => $location->BoundingBox->LowerLeft->Lon_WGS84,
'north' => $location->BoundingBox->UpperRight->Lat_WGS84,
];

$results[] = Address::createFromArray([
'providedBy' => $this->getName(),
'latitude' => $coordinates->Lat_WGS84,
'longitude' => $coordinates->Lon_WGS84,
'streetNumber' => $housenumber,
'streetName' => $streetName,
'locality' => $municipality,
'postalCode' => $zipcode,
'countryCode' => $countryCode,
'bounds' => $bounds,
]);

$builder = new AddressBuilder($this->getName());
$builder->setCoordinates($location->Location->Lat_WGS84, $location->Location->Lon_WGS84)
->setStreetNumber($housenumber)
->setStreetName($streetName)
->setLocality($municipality)
->setPostalCode($zipcode)
->setBounds(
$location->BoundingBox->LowerLeft->Lat_WGS84,
$location->BoundingBox->LowerLeft->Lon_WGS84,
$location->BoundingBox->UpperRight->Lat_WGS84,
$location->BoundingBox->UpperRight->Lon_WGS84
);

$results[] = $builder->build();
}

return new AddressCollection($results);
Expand All @@ -120,31 +115,25 @@ public function reverseQuery(ReverseQuery $query): Collection

$results = [];
foreach ($json->LocationResult as $location) {
$coordinates = $location->Location;
$streetName = !empty($location->Thoroughfarename) ? $location->Thoroughfarename : null;
$housenumber = !empty($location->Housenumber) ? $location->Housenumber : null;
$municipality = !empty($location->Municipality) ? $location->Municipality : null;
$zipcode = !empty($location->Zipcode) ? $location->Zipcode : null;
$countryCode = 'BE';

$bounds = [
'west' => $location->BoundingBox->LowerLeft->Lon_WGS84,
'south' => $location->BoundingBox->UpperRight->Lat_WGS84,
'east' => $location->BoundingBox->LowerLeft->Lon_WGS84,
'north' => $location->BoundingBox->UpperRight->Lat_WGS84,
];

$results[] = Address::createFromArray([
'providedBy' => $this->getName(),
'latitude' => $coordinates->Lat_WGS84,
'longitude' => $coordinates->Lon_WGS84,
'streetNumber' => $housenumber,
'streetName' => $streetName,
'locality' => $municipality,
'postalCode' => $zipcode,
'countryCode' => $countryCode,
'bounds' => $bounds,
]);

$builder = new AddressBuilder($this->getName());
$builder->setCoordinates($location->Location->Lat_WGS84, $location->Location->Lon_WGS84)
->setStreetNumber($housenumber)
->setStreetName($streetName)
->setLocality($municipality)
->setPostalCode($zipcode)
->setBounds(
$location->BoundingBox->LowerLeft->Lat_WGS84,
$location->BoundingBox->LowerLeft->Lon_WGS84,
$location->BoundingBox->UpperRight->Lat_WGS84,
$location->BoundingBox->UpperRight->Lon_WGS84
);

$results[] = $builder->build();
}

return new AddressCollection($results);
Expand Down

0 comments on commit 0be13b4

Please sign in to comment.