Update: 2026-07-06 01:18:35
This commit is contained in:
@@ -17,32 +17,38 @@
|
||||
* @return array|null Returns ['distance_km' => float, 'duration_min' => float] or null on failure.
|
||||
*/
|
||||
function getOsrmRouteDetails($startLat, $startLng, $endLat, $endLng, $countryCode = 'JO') {
|
||||
// Format: longitude,latitude
|
||||
$coordinates = "{$startLng},{$startLat};{$endLng},{$endLat}";
|
||||
|
||||
// Select Intaleq/Siro OSRM server based on country
|
||||
// Select Intaleq Maps SaaS server based on country
|
||||
switch (strtoupper($countryCode)) {
|
||||
case 'SY':
|
||||
$osrmBaseUrl = "https://routes-syria.siromove.com";
|
||||
$baseUrl = "https://map-syria.siromove.com/api/maps/route";
|
||||
break;
|
||||
case 'EG':
|
||||
$osrmBaseUrl = "https://routes-egypt.siromove.com";
|
||||
$baseUrl = "https://map-egypt.siromove.com/api/maps/route";
|
||||
break;
|
||||
case 'JO':
|
||||
default:
|
||||
$osrmBaseUrl = "https://routesjo.intaleq.xyz";
|
||||
$baseUrl = "https://map-saas.intaleqapp.com/api/maps/route";
|
||||
break;
|
||||
}
|
||||
|
||||
$url = "{$osrmBaseUrl}/route/v1/driving/{$coordinates}?overview=false";
|
||||
$queryParams = http_build_query([
|
||||
'fromLat' => $startLat,
|
||||
'fromLng' => $startLng,
|
||||
'toLat' => $endLat,
|
||||
'toLng' => $endLng
|
||||
]);
|
||||
|
||||
$url = "{$baseUrl}?{$queryParams}";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // 5 seconds timeout
|
||||
|
||||
// Add a User-Agent to avoid being blocked by the public demo server
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, "SiroRideHailingApp/1.0");
|
||||
// Add Intaleq API Key Header
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"x-api-key: in_9478b32836d19cff73db3063"
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
@@ -50,10 +56,9 @@ function getOsrmRouteDetails($startLat, $startLng, $endLat, $endLng, $countryCod
|
||||
|
||||
if ($httpCode === 200 && $response) {
|
||||
$data = json_decode($response, true);
|
||||
if (isset($data['code']) && $data['code'] === 'Ok' && isset($data['routes'][0])) {
|
||||
$route = $data['routes'][0];
|
||||
$distanceMeters = isset($route['distance']) ? (float)$route['distance'] : 0;
|
||||
$durationSeconds = isset($route['duration']) ? (float)$route['duration'] : 0;
|
||||
if (isset($data['distance']) && isset($data['duration'])) {
|
||||
$distanceMeters = (float)$data['distance'];
|
||||
$durationSeconds = (float)$data['duration'];
|
||||
|
||||
return [
|
||||
'distance_km' => round($distanceMeters / 1000, 2),
|
||||
|
||||
Reference in New Issue
Block a user