|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class Reverse |
|
4
|
|
|
* |
|
5
|
|
|
* @package maxh\nominatim |
|
6
|
|
|
* @author Maxime Hélias <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace maxh\Nominatim; |
|
10
|
|
|
|
|
11
|
|
|
use maxh\Nominatim\Exceptions\InvalidParameterException; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Reverse Geocoding a OSM nominatim service for places. |
|
15
|
|
|
* |
|
16
|
|
|
* @see http://wiki.openstreetmap.org/wiki/Nominatim |
|
17
|
|
|
*/ |
|
18
|
|
|
class Reverse extends Query |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* OSM Type accepted (Node/Way/Relation) |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
public $osmType = ['N', 'W', 'R']; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Constructo |
|
30
|
|
|
* @param array $query Default value for this query |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(array $query = []) |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct(); |
|
35
|
|
|
|
|
36
|
|
|
$this->setPath('reverse'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
// -- Builder methods ------------------------------------------------------ |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* [osmType description] |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $type |
|
45
|
|
|
* |
|
46
|
|
|
* @return maxh\Nominatim\Reverse |
|
47
|
|
|
* @throws maxh\Nominatim\Exceptions\InvalidParameterException if osm type is not supported |
|
48
|
|
|
*/ |
|
49
|
|
|
public function osmType($type) |
|
50
|
|
|
{ |
|
51
|
|
|
if(in_array($type, $this->osmType)) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->query['osm_type'] = $type; |
|
54
|
|
|
|
|
55
|
|
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
throw new InvalidParameterException("OSM Type is not supported"); |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* A specific osm node / way / relation to return an address for. |
|
64
|
|
|
* |
|
65
|
|
|
* @param integer $id |
|
66
|
|
|
* |
|
67
|
|
|
* @return maxh\Nominatim\Reverse |
|
68
|
|
|
*/ |
|
69
|
|
|
public function osmId($id) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->query['osm_id'] = $id; |
|
72
|
|
|
|
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* The location to generate an address for |
|
78
|
|
|
* |
|
79
|
|
|
* @param float $lat The latitude |
|
80
|
|
|
* @param float $lon The longitude |
|
81
|
|
|
* |
|
82
|
|
|
* @return maxh\Nominatim\Reverse |
|
83
|
|
|
*/ |
|
84
|
|
|
public function latlon($lat, $lon) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->query['lat'] = $lat; |
|
87
|
|
|
|
|
88
|
|
|
$this->query['lon'] = $lon; |
|
89
|
|
|
|
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Level of detail required where 0 is country and 18 is house/building |
|
95
|
|
|
* |
|
96
|
|
|
* @param integer $zoom |
|
97
|
|
|
* |
|
98
|
|
|
* @return maxh\Nominatim\Reverse |
|
99
|
|
|
*/ |
|
100
|
|
|
public function zoom($zoom) |
|
101
|
|
|
{ |
|
102
|
|
|
$this->query['zoom'] = strval($zoom); |
|
103
|
|
|
|
|
104
|
|
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|