forked from parse-community/parse-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseGeoPoint.php
More file actions
executable file
·105 lines (95 loc) · 1.98 KB
/
Copy pathParseGeoPoint.php
File metadata and controls
executable file
·105 lines (95 loc) · 1.98 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Parse;
use Parse\Internal\Encodable;
/**
* ParseGeoPoint - Representation of a Parse GeoPoint object.
*
* @author Fosco Marotto <fjm@fb.com>
*/
class ParseGeoPoint implements Encodable
{
/**
* The latitude.
*
* @var float
*/
private $latitude;
/**
* The longitude.
*
* @var float
*/
private $longitude;
/**
* Create a Parse GeoPoint object.
*
* @param float $lat Latitude.
* @param float $lon Longitude.
*/
public function __construct($lat, $lon)
{
$this->setLatitude($lat);
$this->setLongitude($lon);
}
/**
* Returns the Latitude value for this GeoPoint.
*
* @return float
*/
public function getLatitude()
{
return $this->latitude;
}
/**
* Set the Latitude value for this GeoPoint.
*
* @param $lat
*
* @throws ParseException
*/
public function setLatitude($lat)
{
if ($lat > 90.0 || $lat < -90.0) {
throw new ParseException('Latitude must be within range [-90.0, 90.0]');
}
$this->latitude = $lat;
}
/**
* Returns the Longitude value for this GeoPoint.
*
* @return float
*/
public function getLongitude()
{
return $this->longitude;
}
/**
* Set the Longitude value for this GeoPoint.
*
* @param $lon
*
* @throws ParseException
*/
public function setLongitude($lon)
{
if ($lon > 180.0 || $lon < -180.0) {
throw new ParseException(
'Longitude must be within range [-180.0, 180.0]'
);
}
$this->longitude = $lon;
}
/**
* Encode to associative array representation.
*
* @return array
*/
public function _encode()
{
return [
'__type' => 'GeoPoint',
'latitude' => $this->latitude,
'longitude' => $this->longitude,
];
}
}