1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP Exif Coordinates ValueObject |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/PHPExif/php-exif-common for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2016 Tom Van Herreweghe <[email protected]> |
7
|
|
|
* @license http://github.com/PHPExif/php-exif-common/blob/master/LICENSE MIT License |
8
|
|
|
* @category PHPExif |
9
|
|
|
* @package Common |
10
|
|
|
* @codeCoverageIgnore |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace PHPExif\Common\Data\ValueObject; |
14
|
|
|
|
15
|
|
|
use \InvalidArgumentException; |
16
|
|
|
use \JsonSerializable; |
17
|
|
|
use \RuntimeException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Coordinates class |
21
|
|
|
* |
22
|
|
|
* A value object to describe the coordinates of an image |
23
|
|
|
* |
24
|
|
|
* @category PHPExif |
25
|
|
|
* @package Common |
26
|
|
|
*/ |
27
|
|
|
class Coordinates implements JsonSerializable |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* The latitude |
31
|
|
|
* |
32
|
|
|
* @var DigitalDegrees |
33
|
|
|
*/ |
34
|
|
|
private $latitude; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The longitude |
38
|
|
|
* |
39
|
|
|
* @var DigitalDegrees |
40
|
|
|
*/ |
41
|
|
|
private $longitude; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param DigitalDegrees $latitude |
45
|
|
|
* @param DigitalDegrees $longitude |
46
|
|
|
*/ |
47
|
|
|
public function __construct(DigitalDegrees $latitude, DigitalDegrees $longitude) |
48
|
|
|
{ |
49
|
|
|
$this->setLatitude($latitude); |
50
|
|
|
$this->setLongitude($longitude); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Sets the latitude |
55
|
|
|
* |
56
|
|
|
* @param DigitalDegrees $latitude |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
private function setLatitude(DigitalDegrees $latitude) |
61
|
|
|
{ |
62
|
|
|
$this->latitude = $latitude; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Sets the longitude |
67
|
|
|
* |
68
|
|
|
* @param DigitalDegrees $longitude |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
private function setLongitude(DigitalDegrees $longitude) |
73
|
|
|
{ |
74
|
|
|
$this->longitude = $longitude; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Getter for latitude |
79
|
|
|
* |
80
|
|
|
* @return DigitalDegrees |
81
|
|
|
*/ |
82
|
|
|
public function getLatitude() |
83
|
|
|
{ |
84
|
|
|
return $this->latitude; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Getter for longitude |
89
|
|
|
* |
90
|
|
|
* @return DigitalDegrees |
91
|
|
|
*/ |
92
|
|
|
public function getLongitude() |
93
|
|
|
{ |
94
|
|
|
return $this->longitude; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Creates a new instance from given Coordinates object |
99
|
|
|
* |
100
|
|
|
* @param Coordinates $coordinates |
101
|
|
|
* |
102
|
|
|
* @return Coordinates |
103
|
|
|
*/ |
104
|
|
|
public static function fromCoordinates(Coordinates $coordinates) |
105
|
|
|
{ |
106
|
|
|
return new self( |
107
|
|
|
(clone $coordinates->getLatitude()), |
108
|
|
|
(clone $coordinates->getLongitude()) |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @inheritDoc |
114
|
|
|
* |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function jsonSerialize() |
118
|
|
|
{ |
119
|
|
|
return [ |
120
|
|
|
'latitude' => $this->getLatitude(), |
121
|
|
|
'longitude' => $this->getLongitude(), |
122
|
|
|
]; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Returns string representation |
127
|
|
|
* |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
public function __toString() |
131
|
|
|
{ |
132
|
|
|
return sprintf( |
133
|
|
|
'%1$s,%2$s', |
134
|
|
|
(string) $this->getLatitude(), |
135
|
|
|
(string) $this->getLongitude() |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|