forked from kkaiser1952/NCM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetLatLonFromW3W.php
45 lines (30 loc) · 1.36 KB
/
getLatLonFromW3W.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
// Get the lat/lon from a what3words address
// https://api.what3words.com/v3/convert-to-coordinates?words=filled.count.soap&key=[API-KEY]
// https://api.what3words.com/v3/convert-to-coordinates?key=5WHIM4GD&words=easily.hardest.ended
// {"country":"US","square":{"southwest":{"lng":-94.602915,"lat":39.202889},"northeast":{"lng":-94.60288,"lat":39.202916}},"nearestPlace":"Riverside, Missouri","coordinates":{"lng":-94.602897,"lat":39.202903},"words":"easily.hardest.ended","language":"en","map":"https:\/\/w3w.co\/easily.hardest.ended"};
// example address
// $w3w = "easily.hardest.ended";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.what3words.com/v3/convert-to-coordinates?key=5WHIM4GD&words=$w3w",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
$w3wLL = json_decode($response, true);
$koords = $w3wLL['coordinates'];
echo "<PRE>".json_encode($koords, JSON_PRETTY_PRINT)."</PRE><br>";
} // end else
// End what3word stuff
?>