Beispiel #1
0
 public function read()
 {
     $data = TDT::HttpRequest("http://*****:*****@m.velo-antwerpen.be/data/stations.json");
     $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->latitude;
         $station->longitude = $sourceStation->longitude;
         $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);
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
<?php

/*

$lat1 = 55.66157579999999;
$lon1 = 12.4049744;
*/
$lat1 = $_POST['lat'];
$lon1 = $_POST['lon'];
require 'gPoint.php';
include 'stations.inc';
$stations = array();
foreach ($stationlist as $uic => $stationinfo) {
    $utm_parts = explode(';', $stationinfo['utm']);
    $station = new gPoint();
    $station->setUTM($utm_parts[0], $utm_parts[1], '32N');
    $station->convertTMtoLL();
    $stations[] = array('uic' => $uic - 8600000, 'name' => $stationinfo['station'], 'distance' => $station->distanceFrom($lon1, $lat1));
}
usort($stations, 'distancesort');
print json_encode($stations);
function distancesort($a, $b)
{
    if ($a['distance'] == $b['distance']) {
        return 0;
    }
    return $a['distance'] < $b['distance'] ? -1 : 1;
}