add getRoute method and format numbers returned
This commit is contained in:
parent
1e3a6dd612
commit
d67db33ed0
@ -19,7 +19,35 @@ class Libs
|
|||||||
if (isset($result['results'][0]['lat']) && isset($result['results'][0]['lon'])) {
|
if (isset($result['results'][0]['lat']) && isset($result['results'][0]['lon'])) {
|
||||||
$lat = $result['results'][0]['lat'];
|
$lat = $result['results'][0]['lat'];
|
||||||
$lon = $result['results'][0]['lon'];
|
$lon = $result['results'][0]['lon'];
|
||||||
return [$lat, $lon];
|
return [number_format($lat, 6), number_format($lon, 6)];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRoute($lat1, $lon1, $lat2, $lon2): ?array
|
||||||
|
{
|
||||||
|
$params = [
|
||||||
|
'waypoints' => "{$lat1},{$lon1}|{$lat2},{$lon2}",
|
||||||
|
'mode' => 'drive',
|
||||||
|
'units' => 'imperial',
|
||||||
|
'format' => 'json',
|
||||||
|
'apiKey' => $_ENV['GEOAPIFY_API_KEY']
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
$url = "https://api.geoapify.com/v1/routing?".http_build_query($params);
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
$result = json_decode($result, true);
|
||||||
|
dd($result);
|
||||||
|
if (isset($result['features'][0]['geometry']['coordinates'])) {
|
||||||
|
$route = $result['features'][0]['geometry']['coordinates'];
|
||||||
|
return $route;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user