swisnl/geocoder-php-nationaal-georegister-provider

PDOK (formerly Nationaal Georegister) provider for Geocoder PHP

1.6.0 2023-04-07 06:54 UTC

This package is auto-updated.

Last update: 2024-11-07 10:44:50 UTC


README

PHP from Packagist Latest Version on Packagist Software License Buy us a tree Build Status Coverage Status Quality Score Total Downloads Made by SWIS

⚠️ Please make sure you update to at least 1.6.0 before August 2023 ⚠️

This is the PDOK (formerly Nationaal Georegister) provider for the PHP Geocoder, which uses the PDOK Locatieserver v3 (Dutch). It can geocode addresses (not IP addresses) and reverse geocode coordinates.

Please note that this provider can only (reverse) geocode addresses in The Netherlands!

Install

Via Composer

$ composer require swisnl/geocoder-php-nationaal-georegister-provider

HTTP Client

PHP Geocoder is decoupled from any HTTP messaging client with the help of PSR-18 HTTP Client. This requires another package providing psr/http-client-implementation. To use Guzzle 7, for example, simply require guzzlehttp/guzzle:

$ composer require guzzlehttp/guzzle

Usage

// Create geocoder
$client = new \GuzzleHttp\Client();
$geocoder = new \Swis\Geocoder\NationaalGeoregister\NationaalGeoregister($client);

// Geocode!
$query = \Geocoder\Query\GeocodeQuery::create(...);
$result = $geocoder->geocodeQuery($query);

Please see PHP Geocoder documentation for more information about using PHP Geocoder with this provider.

Options

This provider accepts extra options in the constructor, or as query data. These options are directly passed to the Locatieserver, which accepts the following options:

These options correspond with the options mentioned in the Locatieserver documentation (Dutch), which describes them in more detail.

Example using extra options:

// On the geocoder instance:
$client = new \GuzzleHttp\Client();
$options = ['fq' => 'bron:BAG'];
$geocoder = new \Swis\Geocoder\NationaalGeoregister\NationaalGeoregister($client, $options);

// Or just once on the query:
$query = \Geocoder\Query\GeocodeQuery::create(...)->withData('fq', 'bron:BAG');

Response

The geocoder returns a \Geocoder\Model\AddressCollection which is a collection of \Geocoder\Model\Address.

Example response (first \Geocoder\Model\Address from collection) for query "3e Binnenvestgracht 23T1, Leiden" using this provider:

$address->getCoordinates() => \Geocoder\Model\Coordinates
$address->getLatitude() => 52.164203
$address->getLongitude() => 4.49202289
$address->getBounds() => null (unavailable)
$address->getStreetNumber() => '23T-1'
$address->getStreetName() => '3e Binnenvestgracht'
$address->getPostalCode() => '2312NR'
$address->getLocality() => 'Leiden'
$address->getSubLocality() => null (unavailable)
$address->getAdminLevels()->get(2)->getName() => 'Leiden'
$address->getAdminLevels()->get(2)->getCode() => '0546'
$address->getAdminLevels()->get(1)->getName() => 'Zuid-Holland'
$address->getAdminLevels()->get(1)->getCode() => 'PV28'
$address->getCountry() => 'Netherlands' (static)
$address->getCountryCode() => 'NL' (static)
$address->getTimezone() => 'Europe/Amsterdam' (static)

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email security@swis.nl instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

SWIS ❤️ Open Source

SWIS is a web agency from Leiden, the Netherlands. We love working with open source software.