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