1
|
|
|
<?php namespace Arcanedev\GeoLocation\Google\DistanceMatrix; |
2
|
|
|
|
3
|
|
|
use Arcanedev\GeoLocation\Google\AbstractResponse; |
4
|
|
|
use Illuminate\Support\Arr; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class DistanceMatrixResponse |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\GeoLocation\Google\DistanceMatrix |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class DistanceMatrixResponse extends AbstractResponse |
13
|
|
|
{ |
14
|
|
|
/* ----------------------------------------------------------------- |
15
|
|
|
| Getters & Setters |
16
|
|
|
| ----------------------------------------------------------------- |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Get the first origin address. |
21
|
|
|
* |
22
|
|
|
* @return string|null |
23
|
|
|
*/ |
24
|
15 |
|
public function getOriginAddress() |
25
|
|
|
{ |
26
|
15 |
|
return Arr::first($this->getOriginAddresses(), null, null); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get the original addresses. |
31
|
|
|
* |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
15 |
|
public function getOriginAddresses() |
35
|
|
|
{ |
36
|
15 |
|
return $this->get('origin_addresses', []); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get the first destination address. |
41
|
|
|
* |
42
|
|
|
* @return string|null |
43
|
|
|
*/ |
44
|
15 |
|
public function getDestinationAddress() |
45
|
|
|
{ |
46
|
15 |
|
return Arr::first($this->getDestinationAddresses(), null, null); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the destination addresses. |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
15 |
|
public function getDestinationAddresses() |
55
|
|
|
{ |
56
|
15 |
|
return $this->get('destination_addresses', []); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get the distance (text or value). |
61
|
|
|
* |
62
|
|
|
* @param bool $text |
63
|
|
|
* |
64
|
|
|
* @return string|int |
65
|
|
|
*/ |
66
|
18 |
|
public function getDistance($text = true) |
67
|
|
|
{ |
68
|
18 |
|
return $this->get('rows.0.elements.0.distance.'. ($text ? 'text' : 'value')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the duration (text or value). |
73
|
|
|
* |
74
|
|
|
* @param bool $text |
75
|
|
|
* |
76
|
|
|
* @return string|int |
77
|
|
|
*/ |
78
|
18 |
|
public function getDuration($text = true) |
79
|
|
|
{ |
80
|
18 |
|
return $this->get('rows.0.elements.0.duration.'. ($text ? 'text' : 'value')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/* ----------------------------------------------------------------- |
84
|
|
|
| Main Methods |
85
|
|
|
| ----------------------------------------------------------------- |
86
|
|
|
*/ |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Convert the object to array. |
90
|
|
|
* |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
6 |
|
public function toArray() |
94
|
|
|
{ |
95
|
|
|
return [ |
96
|
6 |
|
'origin' => $this->getOriginAddress(), |
97
|
6 |
|
'destination' => $this->getDestinationAddress(), |
98
|
|
|
'distance' => [ |
99
|
6 |
|
'text' => $this->getDistance(), |
100
|
6 |
|
'value' => $this->getDistance(false), |
101
|
2 |
|
], |
102
|
|
|
'duration' => [ |
103
|
6 |
|
'text' => $this->getDuration(), |
104
|
6 |
|
'value' => $this->getDuration(false), |
105
|
2 |
|
], |
106
|
2 |
|
]; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|