public function read() { $data = TDT::HttpRequest("http://www.mobielbrussel.irisnet.be/villo/json/"); $decoded = json_decode($data->data); //todo: convert to wished format $result = array(); $gpoint = new gPoint(); foreach ($decoded->features as $feature) { $station = new Object(); $station->name = $feature->properties->NAME; $station->freebikes = $feature->properties->FREEBK; $station->freespots = $feature->properties->FREEBS; $station->state = $feature->properties->STATE; // Configure the gPoint library to use the Lambert Projection for Belgium $gpoint->configLambertProjection(150000.013, 5400088.438, 4.367487, 90, 49.833333, 51.166666); $x = $feature->geometry->coordinates[0]; $y = $feature->geometry->coordinates[1]; $gpoint->setLambert($x, $y); // Convert the Lambert Coordinates to Latitude and Longitude (using the gPoint Library) $gpoint->convertLCCtoLL(); $station->latitude = $gpoint->lat; $station->longitude = $gpoint->long; 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); }