1 | <?php |
||
17 | class LatLong |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Validation regex for Latitude parameters. |
||
22 | */ |
||
23 | const LAT_VALIDATION_REGEX = "/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/"; |
||
24 | |||
25 | /** |
||
26 | * Validation regex for Longitude parameters. |
||
27 | */ |
||
28 | const LNG_VALIDATION_REGEX = "/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/"; |
||
29 | |||
30 | /** |
||
31 | * The latitude coordinate. |
||
32 | * @var double |
||
33 | */ |
||
34 | protected $latitude; |
||
35 | |||
36 | /** |
||
37 | * The longitude coordinate. |
||
38 | * @var double |
||
39 | */ |
||
40 | protected $longitude; |
||
41 | |||
42 | /** |
||
43 | * Create a new latitude and longitude object. |
||
44 | * @param double $lat The latitude coordinate. |
||
45 | * @param double $lng The longitude coordinate. |
||
46 | * @throws \InvalidArgumentException |
||
47 | */ |
||
48 | 4 | public function __construct($lat, $lng) |
|
59 | |||
60 | /** |
||
61 | * Validates the Latitude value. |
||
62 | * |
||
63 | * @return boolean |
||
64 | */ |
||
65 | 4 | private function validateLat() |
|
72 | |||
73 | /** |
||
74 | * Validates the Longitude value. |
||
75 | * @return boolean True if validation passes. |
||
76 | */ |
||
77 | 2 | private function validateLng() |
|
84 | |||
85 | /** |
||
86 | * Returns the current Latitude coordinate. |
||
87 | * @return double |
||
88 | */ |
||
89 | 16 | public function getLatitude() |
|
93 | |||
94 | /** |
||
95 | * Returns the current Longitude coordinate. |
||
96 | * @return double |
||
97 | */ |
||
98 | 16 | public function getLongitude() |
|
102 | |||
103 | /** |
||
104 | * Alias of getLatitude |
||
105 | * @return double |
||
106 | */ |
||
107 | 15 | public function lat() |
|
111 | |||
112 | /** |
||
113 | * Alias of getLongitude |
||
114 | * @return double |
||
115 | */ |
||
116 | 15 | public function lng() |
|
120 | } |
||
121 |