Conditions | 3 |
Paths | 3 |
Total Lines | 20 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | public function getCoordinates(String $search) : array |
||
23 | { |
||
24 | $key = $this->config; |
||
25 | |||
26 | if (is_string($search)) { |
||
|
|||
27 | $details = json_decode(file_get_contents("https://api.opencagedata.com/geocode/v1/json?q=$search&key={$key}")); |
||
28 | $results = $details->results; |
||
29 | if (isset($results[0]->geometry)) { |
||
30 | $valid = "Valid"; |
||
31 | $lat = $results[0]->geometry->lat; |
||
32 | $long = $results[0]->geometry->lng; |
||
33 | } else { |
||
34 | $valid = "Not valid, showing Gold Coast instead"; |
||
35 | $lat = -28.016666; |
||
36 | $long = 153.399994; |
||
37 | } |
||
38 | return [ |
||
39 | "valid" => $valid, |
||
40 | "lat" => $lat, |
||
41 | "long" => $long |
||
42 | ]; |
||
46 |