first draft of case addresses and itineraries
This commit is contained in:
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Libs;
|
||||
|
||||
use App\Entity\Location;
|
||||
|
||||
class Libs
|
||||
{
|
||||
public static function getLatLonFromGeoapify($address): ?array
|
||||
@ -24,7 +26,7 @@ class Libs
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getRoute($lat1, $lon1, $lat2, $lon2): ?array
|
||||
public static function getRoute($lat1, $lon1, $lat2, $lon2): ?Route
|
||||
{
|
||||
$params = [
|
||||
'waypoints' => "{$lat1},{$lon1}|{$lat2},{$lon2}",
|
||||
@ -34,7 +36,6 @@ class Libs
|
||||
'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);
|
||||
@ -43,10 +44,18 @@ class Libs
|
||||
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'];
|
||||
$route = new Route(json_decode($result));
|
||||
|
||||
if (is_a($route, Route::class)) {
|
||||
return $route;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getRouteDistance(Location $origin, Location $destination): ?Route
|
||||
{
|
||||
$route = self::getRoute($origin->getLat(), $origin->getLon(), $destination->getLat(), $destination->getLon());
|
||||
if ($route) {
|
||||
return $route;
|
||||
}
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user