wimski / nominatim-geocoding-api-client
Nominatim Geocoding API Client
Installs: 3 583
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- myclabs/php-enum: ^1.8
- php-http/discovery: ^1.13
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
Requires (Dev)
- mockery/mockery: ^1.5
- nyholm/psr7: ^1.5
- phpstan/phpstan: ^1.4
- phpstan/phpstan-mockery: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- swisnl/php-http-fixture-client: ^3.0
This package is auto-updated.
Last update: 2024-10-22 14:27:13 UTC
README
Nominatim Geocoding API Client
Changelog
Usage
Install package
composer require wimski/nominatim-geocoding-api-client
Example
use Wimski\Nominatim\Client; use Wimski\Nominatim\Config\NominatimConfig; use Wimski\Nominatim\GeocoderServices\NominatimGeocoderService; use Wimski\Nominatim\RequestParameters\ForwardGeocodingQueryRequestParameters; use Wimski\Nominatim\Transformers\GeocodingResponseTransformer; $config = new NominatimConfig( 'my-custom-user-agent', 'email@provider.net', ); $service = new NominatimGeocoderService( new Client(), new GeocodingResponseTransformer(), $config, ); $requestParameters = ForwardGeocodingQueryRequestParameters::make('some query') ->addCountryCode('nl') ->includeAddressDetails(); $response = $service->requestForwardGeocoding($requestParameters); // Get data from the response $latitude = $response->getItems()[0]->getCoordinate()->getLatitude();
PSR HTTP
The Client
class uses Discovery by default to get instances of the following contracts:
Psr\Http\Client\ClientInterface
Psr\Http\Message\RequestFactoryInterface
Psr\Http\Message\UriFactoryInterface
This means that you need to include (a) PSR compatible package(s) in your project.
If you already have setup a specific HTTP client configuration in your project,
which you would also like to use for Nominatim requests,
you can pass that as a constructor argument to the Client
:
$service = new NominatimGeocoderService( new Client($myCustomPsrHttpClient), new GeocodingResponseTransformer(), new NominatimConfig('user-agent', 'email@provider.net'), );
Services
Services for the following providers are currently available:
- Nominatim
- LocationIQ
- Generic: without any implementation specific headers or parameters.
Custom services can easily be created by extending the AbstractGeocoderService
as long as the provider implements the Nominatim spec correctly.
PHPUnit
composer run phpunit
PHPStan
composer run phpstan
Credits
License
The MIT License (MIT). Please see License File for more information.