-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
56 lines (45 loc) · 1.62 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
class YandexTaxiApiClient {
private $clid;
private $apiKey;
private $classStr;
public function __construct($clid, $apiKey, $classStr) {
$this->clid = $clid;
$this->apiKey = $apiKey;
$this->classStr = $classStr;
}
public function getRouteInfo($fromLonLat, $toLonLat) {
$url = 'https://taxi-routeinfo.taxi.yandex.net/taxi_info';
$options = array(
'clid' => $this->clid,
'apikey' => $this->apiKey,
'rll' => $fromLonLat . '~' . $toLonLat,
'class_str' => $this->classStr,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($options));
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
throw new Exception("Curl request failed: " . curl_error($ch));
}
return $response;
}
}
try {
$clid = 'your_clid_here';
$apiKey = 'your_api_key_here';
// Тип запроса: Эконом, Бизнес, Курьер и.д
$classStr = 'express';
// Координаты от и до
$fromLonLat = '76.93361121975246,43.230385838927816';
$toLonLat = '76.95132452808683,43.24996393218453';
$client = new YandexTaxiApiClient($clid, $apiKey, $classStr);
$response = $client->getRouteInfo($fromLonLat, $toLonLat);
// Вернуть результат запроса для дальнейшей обработки
echo $response;
} catch (Exception $e) {
echo "Произошла ошибка: " . $e->getMessage();
}
?>