localgovdrupal / localgov_os_places_geocoder_provider
Temporary home for our OS Places Geocoder provider.
Installs: 29 262
Dependents: 1
Suggesters: 1
Security: 0
Stars: 1
Watchers: 8
Forks: 0
Open Issues: 2
Requires
- geocoder-php/common-http: ^4.1
- willdurand/geocoder: ^4.0
Requires (Dev)
- geocoder-php/provider-integration-tests: ^1.0
- php-http/curl-client: ^2.2
- php-http/message: ^1.0
- phpunit/phpunit: ^9.5
Provides
This package is auto-updated.
Last update: 2024-12-18 19:14:35 UTC
README
Temporary home for our OS Places PHP Geocoder provider.
PHP Geocoder plugin for the Ordnance Survey Places API. Looks up addresses based on the given street address or postcode. Resultant addresses include both Easting and Northing as well as latitude and longitude as location coordinates. The values of Easting and Northing are in the All numeric grid reference format.
Search results can be filtered for a single local authority based on its Local custodian code.
This Geocoder requires an API key.
Installation
$ composer require localgovdrupal/localgov_os_places_geocoder_provider
Sample Usage
Setup
$ composer require localgovdrupal/localgov_os_places_geocoder_provider:1.x-dev php-http/guzzle6-adapter php-http/message
Code
use Http\Adapter\Guzzle6\Client as Guzzle;
use Geocoder\Query\GeocodeQuery;
use LocalgovDrupal\OsPlacesGeocoder\Provider\OsPlacesGeocoder;
$http_client = new Guzzle();
$generic_query_url = 'https://api.os.uk/search/places/v1/find';
$postcode_query_url = 'https://api.os.uk/search/places/v1/postcode';
$our_api_key = 'API-KEY-GOES-HERE';
$provider = new OsPlacesGeocoder($http_client, $generic_query_url, $postcode_query_url, $our_api_key);
$result = $provider->geocodeQuery(GeocodeQuery::create('BN1 1JE'));
$address = $result->first()->toArray();
print_r($address);
// Restrict lookup to a single local authority.
$query = GeocodeQuery::create('Brighton pier')->withData('local_custodian_code', 1445);
$result = $provider->geocodeQuery($query);
$address = $result->first()->toArray();
print_r($address);