-
Notifications
You must be signed in to change notification settings - Fork 3
/
Velo.class.php
89 lines (72 loc) · 2.64 KB
/
Velo.class.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
<?php
/**
*
* @package packages/Bikes
* @copyright (C) 2012 by iRail vzw/asbl
* @license AGPLv3
* @author Pieter Colpaert <pieter aŧ iRail.be>
*/
class BikesVelo extends AReader{
public function __construct($package, $resource, $RESTparameters) {
parent::__construct($package, $resource, $RESTparameters);
$this->lat = null;
$this->long = null;
$this->offset = 0;
$this->rowcount = 1024;
}
public static function getParameters(){
return array( "lat" => "Latitude"
,"long" => "Longitude"
,"offset" => "Offset"
,"rowcount" => "Rowcount");
}
public static function getRequiredParameters(){
return array();
}
public function setParameter($key,$val){
if($key == "lat") {
$this->lat = $val;
} else if ($key == "long") {
$this->long = $val;
} else if ($key == "offset") {
$this->offset = $val;
} else if ($key == "rowcount") {
$this->rowcount = $val;
}
}
public function read(){
$data = TDT::HttpRequest("https://www.velo-antwerpen.be/availability_map/getJsonObject");
$decoded = json_decode($data->data);
//todo: convert to wished format
$result = array();
$gpoint = new gPoint();
foreach($decoded as $sourceStation) {
$station = new Object();
$station->name = $sourceStation->name;
$station->freebikes = $sourceStation->bikes;
$station->freespots = $sourceStation->slots;
$station->state = $sourceStation->status;
$station->latitude = $sourceStation->lat;
$station->longitude = $sourceStation->lon;
$gpoint->setLongLat($station->longitude, $station->latitude);
if($this->lat != null && $this->long != null) {
$station->distance = $gpoint->distanceFrom($this->long, $this->lat);
}
array_push($result, $station);
}
function compare($a, $b) {
if ($a->distance == $b->distance) {
return 0;
}
return ($a->distance < $b->distance) ? -1 : 1;
}
if($this->lat != null && $this->long != null) {
usort($result, "compare");
}
return array_slice($result, $this->offset, $this->rowcount);
}
public static function getDoc(){
return "This resource contains dynamic information about the availability of bikes in Antwerp";
}
}
?>