|
1
|
|
|
<?php namespace Arcanedev\GeoLocation\Google\Geocoding; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\GeoLocation\Entities\Coordinates\Position; |
|
4
|
|
|
use Arcanedev\GeoLocation\Entities\Coordinates\Viewport; |
|
5
|
|
|
use Arcanedev\GeoLocation\Google\AbstractResponse; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class GeocodingResponse |
|
9
|
|
|
* |
|
10
|
|
|
* @package Arcanedev\GeoLocation\Google\Geocoding |
|
11
|
|
|
* @author ARCANEDEV <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class GeocodingResponse extends AbstractResponse |
|
14
|
|
|
{ |
|
15
|
|
|
/* ----------------------------------------------------------------- |
|
16
|
|
|
| Getters & Setters |
|
17
|
|
|
| ----------------------------------------------------------------- |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Get the formatted address. |
|
22
|
|
|
* |
|
23
|
|
|
* @return string|null |
|
24
|
|
|
*/ |
|
25
|
12 |
|
public function getFormattedAddress() |
|
26
|
|
|
{ |
|
27
|
12 |
|
return $this->get('results.0.formatted_address'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get the separate address components. |
|
32
|
|
|
* |
|
33
|
|
|
* @return array |
|
34
|
|
|
*/ |
|
35
|
9 |
|
public function getAddressComponents() |
|
36
|
|
|
{ |
|
37
|
9 |
|
return $this->get('results.0.address_components', []); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Get the location's position. |
|
42
|
|
|
* |
|
43
|
|
|
* @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position |
|
44
|
|
|
*/ |
|
45
|
12 |
|
public function getLocationPosition() |
|
46
|
|
|
{ |
|
47
|
12 |
|
return Position::createFromArray( |
|
48
|
12 |
|
$this->get('results.0.geometry.location', []) |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get the location's type. |
|
54
|
|
|
* |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
9 |
|
public function getLocationType() |
|
58
|
|
|
{ |
|
59
|
9 |
|
return $this->get('results.0.geometry.location_type'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get the viewport coordinates. |
|
64
|
|
|
* |
|
65
|
|
|
* @return \Arcanedev\GeoLocation\Entities\Coordinates\Viewport |
|
66
|
|
|
*/ |
|
67
|
9 |
|
public function getViewport() |
|
68
|
|
|
{ |
|
69
|
9 |
|
return Viewport::create( |
|
70
|
9 |
|
Position::createFromArray($this->get('results.0.geometry.viewport.northeast', [])), |
|
71
|
9 |
|
Position::createFromArray($this->get('results.0.geometry.viewport.southwest', [])) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get the place id. |
|
77
|
|
|
* |
|
78
|
|
|
* @return string|null |
|
79
|
|
|
*/ |
|
80
|
9 |
|
public function getPlaceId() |
|
81
|
|
|
{ |
|
82
|
9 |
|
return $this->get('results.0.place_id'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/* ----------------------------------------------------------------- |
|
86
|
|
|
| Other Methods |
|
87
|
|
|
| ----------------------------------------------------------------- |
|
88
|
|
|
*/ |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Convert the object to array. |
|
92
|
|
|
* |
|
93
|
|
|
* @return array |
|
94
|
|
|
*/ |
|
95
|
6 |
|
public function toArray() |
|
96
|
|
|
{ |
|
97
|
|
|
return [ |
|
98
|
6 |
|
'formatted_address' => $this->getFormattedAddress(), |
|
99
|
6 |
|
'address_components' => $this->getAddressComponents(), |
|
100
|
6 |
|
'location_position' => $this->getLocationPosition()->toArray(), |
|
101
|
6 |
|
'location_type' => $this->getLocationType(), |
|
102
|
6 |
|
'viewport' => $this->getViewport()->toArray(), |
|
103
|
6 |
|
'place_id' => $this->getPlaceId(), |
|
104
|
|
|
]; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|