Skip to content

Commit 81c0be3

Browse files
authored
Merge pull request #2 from Muffinman/feature/geocoding
Adding UK Specific Geocoding APIs
2 parents 02a14f2 + f02a137 commit 81c0be3

File tree

6 files changed

+346
-1
lines changed

6 files changed

+346
-1
lines changed

README.md

+38-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ $result = (new \Baikho\Loqate\Address\Retrieve('API Key'))
4545

4646
### Geocoding API
4747

48-
Currently only [Distance](https://www.loqate.com/resources/support/apis/DistancesAndDirections/Interactive/Distance/1/) and [Directions](https://www.loqate.com/resources/support/apis/DistancesAndDirections/Interactive/Directions/2/) APIs are supported.
48+
The only APIs currently supported are
49+
50+
- [Distance](https://www.loqate.com/resources/support/apis/DistancesAndDirections/Interactive/Distance/1/)
51+
- [Directions](https://www.loqate.com/resources/support/apis/DistancesAndDirections/Interactive/Directions/2/)
52+
- [UK Find](https://www.loqate.com/resources/support/apis/Geocoding/UK/Find/2/)
53+
- [UK Geocode](https://www.loqate.com/resources/support/apis/Geocoding/UK/Geocode/2.1/)
54+
- [UK Retrieve](https://www.loqate.com/resources/support/apis/Geocoding/UK/Retrieve/2/)
4955

5056
#### Calculate distance between two points.
5157

@@ -67,6 +73,37 @@ $result = $loqate->geocoding()->directions('51.4733514399,-0.00088499646', '51.4
6773
$result = $loqate->geocoding()->directions('SE10 8XJ', 'SW1A 0AA');
6874
```
6975

76+
#### Find a UK Place or Location
77+
78+
This can be a full or partial postcode, a place name or street comma town.
79+
80+
```php
81+
$result = $loqate->geocoding()->ukFind('London');
82+
```
83+
84+
#### Geocode a UK Place or Location
85+
86+
This can be a full or partial postcode, a place name or street comma town.
87+
88+
```php
89+
$result = $loqate->geocoding()->ukGeocode('London');
90+
```
91+
92+
#### Retrieve a UK Place or Location
93+
94+
This can be a full or partial postcode, a place name or street comma town.
95+
96+
```php
97+
$result = $loqate->geocoding()->ukRetrieve('XX|XX|XXX|XXXXXXXXXX');
98+
```
99+
#### Reverse Geocode a position to Address or Location
100+
101+
Returns the nearest address or location to the given coordinates. A postcode or coordinates (latitude, longitude or easting, nothing) of the centre of the search.
102+
103+
```php
104+
$result = $loqate->geocoding()->ukReverseGeocode('51.4733514399,-0.00088499646');
105+
```
106+
70107
### Email Verification API
71108

72109
#### Validate Email Address:

src/Geocoding/GeocodingHandler.php

+48
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,52 @@ public function distance(string $start, string $finish)
5050
{
5151
return (new InteractiveDistance($this->key, $start, $finish))->makeRequest();
5252
}
53+
54+
/**
55+
* UK Find v2
56+
*
57+
* @param string $location
58+
* @return mixed
59+
* @throws \GuzzleHttp\Exception\GuzzleException
60+
*/
61+
public function ukFind(string $location)
62+
{
63+
return (new UKFind($this->key, $location))->makeRequest();
64+
}
65+
66+
/**
67+
* UK Geocode v2.1
68+
*
69+
* @param string $location
70+
* @return mixed
71+
* @throws \GuzzleHttp\Exception\GuzzleException
72+
*/
73+
public function ukGeocode(string $location)
74+
{
75+
return (new UKGeocode($this->key, $location))->makeRequest();
76+
}
77+
78+
/**
79+
* UK Retrieve v2
80+
*
81+
* @param string $id
82+
* @return mixed
83+
* @throws \GuzzleHttp\Exception\GuzzleException
84+
*/
85+
public function ukRetrieve(string $id)
86+
{
87+
return (new UKRetrieve($this->key, $id))->makeRequest();
88+
}
89+
90+
/**
91+
* UK Reverse Geocode v1.1
92+
*
93+
* @param string $centrePoint
94+
* @return mixed
95+
* @throws \GuzzleHttp\Exception\GuzzleException
96+
*/
97+
public function ukReverseGeocode(string $centrePoint)
98+
{
99+
return (new UKGeocode($this->key, $centrePoint))->makeRequest();
100+
}
53101
}

src/Geocoding/UKFind.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Baikho\Loqate\Geocoding;
6+
7+
use Baikho\Loqate\BaseClient;
8+
9+
/**
10+
* Class UK Find v2.
11+
*
12+
* @package Baikho\Loqate\Geocoding
13+
* @see https://www.loqate.com/resources/support/apis/Geocoding/UK/Find/2/
14+
*/
15+
class UKFind extends BaseClient
16+
{
17+
18+
/**
19+
* The location to geocode. This can be a full or partial postcode, a place name or street comma town.
20+
*
21+
* @var string|null
22+
*/
23+
protected ?string $location;
24+
25+
/**
26+
* Find constructor.
27+
*
28+
* @param string $key
29+
* @param string|null $location
30+
*/
31+
public function __construct(string $key, string $location = null)
32+
{
33+
parent::__construct($key);
34+
$this->location = $location;
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function getUri(): string
41+
{
42+
return 'Geocoding/UK/Find/v2/';
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function setParams(array $parameters): self
49+
{
50+
$this->location = $parameters['location'] ?? null;
51+
return $this;
52+
}
53+
54+
/**
55+
* Sets the location.
56+
*
57+
* @param string $location
58+
* @return UKFind
59+
*/
60+
public function setLocation(string $location): UKFind
61+
{
62+
$this->location = $location;
63+
return $this;
64+
}
65+
}

src/Geocoding/UKGeocode.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Baikho\Loqate\Geocoding;
6+
7+
use Baikho\Loqate\BaseClient;
8+
9+
/**
10+
* Class UK Geocode v2.1.
11+
*
12+
* @package Baikho\Loqate\Geocoding
13+
* @see https://www.loqate.com/resources/support/apis/Geocoding/UK/Geocode/2.1/
14+
*/
15+
class UKGeocode extends BaseClient
16+
{
17+
18+
/**
19+
* The location to geocode. This can be a full or partial postcode, a place name, street comma town, address (comma separated lines) or an ID from PostcodeAnywhere/Find web services.
20+
*
21+
* @var string|null
22+
*/
23+
protected ?string $location;
24+
25+
/**
26+
* Find constructor.
27+
*
28+
* @param string $key
29+
* @param string|null $location
30+
*/
31+
public function __construct(string $key, string $location = null)
32+
{
33+
parent::__construct($key);
34+
$this->location = $location;
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function getUri(): string
41+
{
42+
return 'Geocoding/UK/Geocode/v2.1/';
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function setParams(array $parameters): self
49+
{
50+
$this->location = $parameters['location'] ?? null;
51+
return $this;
52+
}
53+
54+
/**
55+
* Sets the location.
56+
*
57+
* @param string $location
58+
* @return UKGeocode
59+
*/
60+
public function setLocation(string $location): UKGeocode
61+
{
62+
$this->location = $location;
63+
return $this;
64+
}
65+
}

src/Geocoding/UKRetrieve.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Baikho\Loqate\Geocoding;
6+
7+
use Baikho\Loqate\BaseClient;
8+
9+
/**
10+
* Class UK Retrieve v2.
11+
*
12+
* @package Baikho\Loqate\Geocoding
13+
* @see https://www.loqate.com/resources/support/apis/Geocoding/UK/Retrieve/2/
14+
*/
15+
class UKRetrieve extends BaseClient
16+
{
17+
18+
/**
19+
* The location ID to retrieve the coordinates for.
20+
*
21+
* @var string|null
22+
*/
23+
protected ?string $id;
24+
25+
/**
26+
* Find constructor.
27+
*
28+
* @param string $key
29+
* @param string|null $id
30+
*/
31+
public function __construct(string $key, string $id = null)
32+
{
33+
parent::__construct($key);
34+
$this->id = $id;
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function getUri(): string
41+
{
42+
return 'Geocoding/UK/Retrieve/v2/';
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function setParams(array $parameters): self
49+
{
50+
$this->id = $parameters['id'] ?? null;
51+
return $this;
52+
}
53+
54+
/**
55+
* Sets the location ID.
56+
*
57+
* @param string $id
58+
* @return UKRetrieve
59+
*/
60+
public function setId(string $id): UKRetrieve
61+
{
62+
$this->id = $id;
63+
return $this;
64+
}
65+
}

src/Geocoding/UKReverseGeocode.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Baikho\Loqate\Geocoding;
6+
7+
use Baikho\Loqate\BaseClient;
8+
9+
/**
10+
* Class UK Reverse Geocode v1.1.
11+
*
12+
* @package Baikho\Loqate\Geocoding
13+
* @see https://www.loqate.com/resources/support/apis/Geocoding/UK/ReverseGeocode/1.1/
14+
*/
15+
class UKReverseGeocode extends BaseClient
16+
{
17+
18+
/**
19+
* A postcode or coordinates (latitude, longitude or easting, nothing) of the centre of the search.
20+
*
21+
* @var string|null
22+
*/
23+
protected ?string $centrePoint;
24+
25+
/**
26+
* Find constructor.
27+
*
28+
* @param string $key
29+
* @param string|null $centrePoint
30+
*/
31+
public function __construct(string $key, string $centrePoint = null)
32+
{
33+
parent::__construct($key);
34+
$this->centrePoint = $centrePoint;
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function getUri(): string
41+
{
42+
return 'Geocoding/UK/ReverseGeocode/v1.1/';
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function setParams(array $parameters): self
49+
{
50+
$this->centrePoint = $parameters['centrePoint'] ?? null;
51+
return $this;
52+
}
53+
54+
/**
55+
* Sets the location.
56+
*
57+
* @param string $centrePoint
58+
* @return UKReverseGeocode
59+
*/
60+
public function setCentrePoint(string $centrePoint): UKReverseGeocode
61+
{
62+
$this->centrePoint = $centrePoint;
63+
return $this;
64+
}
65+
}

0 commit comments

Comments
 (0)