1 | <?php namespace Arcanedev\GeoLocation\Entities; |
||
12 | class Position implements PositionContract |
||
13 | { |
||
14 | /* ----------------------------------------------------------------- |
||
15 | | Properties |
||
16 | | ----------------------------------------------------------------- |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | * The latitude coordinate. |
||
21 | * |
||
22 | * @var \Arcanedev\GeoLocation\Contracts\Entities\Coordinate |
||
23 | */ |
||
24 | protected $latitude; |
||
25 | |||
26 | /** |
||
27 | * The longitude coordinate. |
||
28 | * |
||
29 | * @var \Arcanedev\GeoLocation\Contracts\Entities\Coordinate |
||
30 | */ |
||
31 | protected $longitude; |
||
32 | |||
33 | /* ----------------------------------------------------------------- |
||
34 | | Constructor |
||
35 | | ----------------------------------------------------------------- |
||
36 | */ |
||
37 | |||
38 | /** |
||
39 | * Position constructor. |
||
40 | * |
||
41 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinate $latitude |
||
42 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinate $longitude |
||
43 | */ |
||
44 | 69 | public function __construct(Coordinate $latitude, Coordinate $longitude) |
|
49 | |||
50 | /* ----------------------------------------------------------------- |
||
51 | | Getters & Setters |
||
52 | | ----------------------------------------------------------------- |
||
53 | */ |
||
54 | |||
55 | /** |
||
56 | * Get the latitude coordinate. |
||
57 | * |
||
58 | * @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinate |
||
59 | */ |
||
60 | 57 | public function getLatitude() |
|
64 | |||
65 | /** |
||
66 | * Get the latitude coordinate (alias). |
||
67 | * |
||
68 | * @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinate |
||
69 | */ |
||
70 | 39 | public function lat() |
|
74 | |||
75 | /** |
||
76 | * Set the latitude coordinate. |
||
77 | * |
||
78 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinate $latitude |
||
79 | * |
||
80 | * @return self |
||
81 | */ |
||
82 | 69 | public function setLatitude(Coordinate $latitude) |
|
88 | |||
89 | /** |
||
90 | * Get the longitude coordinate. |
||
91 | * |
||
92 | * @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinate |
||
93 | */ |
||
94 | 57 | public function getLongitude() |
|
98 | |||
99 | /** |
||
100 | * Get the longitude coordinate (alias). |
||
101 | * |
||
102 | * @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinate |
||
103 | */ |
||
104 | 39 | public function lng() |
|
105 | { |
||
106 | 39 | return $this->getLongitude(); |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * Set the longitude coordinate. |
||
111 | * |
||
112 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinate $longitude |
||
113 | * |
||
114 | * @return self |
||
115 | */ |
||
116 | 69 | public function setLongitude(Coordinate $longitude) |
|
122 | |||
123 | /* ----------------------------------------------------------------- |
||
124 | | Main Methods |
||
125 | | ----------------------------------------------------------------- |
||
126 | */ |
||
127 | |||
128 | /** |
||
129 | * Create the position. |
||
130 | * |
||
131 | * @param float $latitude |
||
132 | * @param float $longitude |
||
133 | * |
||
134 | * @return self |
||
135 | */ |
||
136 | 42 | public static function create($latitude, $longitude) |
|
143 | |||
144 | 3 | public static function createFromArray(array $location) |
|
148 | |||
149 | /** |
||
150 | * Convert the object to its JSON representation. |
||
151 | * |
||
152 | * @param int $options |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | 3 | public function toJson($options = 0) |
|
160 | |||
161 | /** |
||
162 | * Convert the object into something JSON serializable. |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | 3 | public function jsonSerialize() |
|
170 | |||
171 | /** |
||
172 | * Get the instance as an array. |
||
173 | * |
||
174 | * @return array |
||
175 | */ |
||
176 | 21 | public function toArray() |
|
183 | } |
||
184 |