forked from bensquire/php-static-maps-generator
/
googlestaticmappathpoint.php
123 lines (105 loc) · 2.34 KB
/
googlestaticmappathpoint.php
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/**
* @author Ben Squire <b.squire@gmail.com>
* @license Apache 2.0
*
* @package GoogleStaticMap
*
* @abstract This class abstracts the path points that can be placed onto the
* Google Static Maps. Either via coordinates or as a string location.
*
* @see https://github.com/bensquire/php-static-maps-generator
*/
class GoogleStaticMapPathPoint {
protected $fLongitude = null;
protected $fLatitude = null;
protected $sLocation = null;
public function __construct($aParams = array()) {
}
/**
* Set the longitude of the map point.
*
* @param float $fLongitude
* @return \GoogleStaticMapPathPoint
*/
public function setLongitude($fLongitude) {
if (!is_numeric($fLongitude)) {
throw new Exception('Invalid longitude value.');
}
$this->fLongitude = (float) $fLongitude;
return $this;
}
/**
* Set the Latitude of the map point.
*
* @param float $fLatitude
* @return \GoogleStaticMapPathPoint
*/
public function setLatitude($fLatitude) {
if (!is_numeric($fLatitude)) {
throw new Exception('Invalid latitude value.');
}
$this->fLatitude = (float) $fLatitude;
return $this;
}
/**
* Set a string location of the map point.
*
* @param string $sLocation
* @return \GoogleStaticMapPathPoint
* @throws Exception
*/
public function setLocation($sLocation) {
if (strlen($sLocation) === 0) {
throw new Exception('No string location provided...');
}
$this->sLocation = (string) $sLocation;
return $this;
}
/**
* Return the float longitude
*
* @return float
*/
public function getLongitude() {
return $this->fLongitude;
}
/**
* Return the float of the latitude
*
* @return float
*/
public function getLatitude() {
return $this->fLatitude;
}
/**
* Return the location string
*
* @return string
*/
public function getLocation() {
return $this->sLocation;
}
/**
* Recombines the coordinates of the map point
*
* @return string
*/
protected function combineCoordinates() {
return $this->fLatitude . ',' . $this->fLongitude;
}
/**
* Build the Map Path Point Part of the URL
*
* @return string
*/
public function build() {
if (strlen($this->fLongitude) > 0 && strlen($this->fLatitude) > 0) {
return $this->combineCoordinates();
} elseif (strlen($this->sLocation) > 0) {
return urlencode($this->sLocation);
}
return '';
}
}
?>