localgovdrupal/localgov_os_places_geocoder_provider

Temporary home for our OS Places Geocoder provider.

1.x-dev 2021-11-29 14:25 UTC

This package is auto-updated.

Last update: 2023-11-29 03:31:27 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.

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 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);