$id, "lastPos" => $pos, "lastLocationUpdate" => $lst, "isRentable" => $rnt, "state" => $act, "name" => $nam, "title" => $tit, "desc" => $des); $id++; } return $latestData; //return array } // THIS ONLY NEEDS TO RUN EVERY 1 or 2 minutes, possibly in the background, als this should construct historical json as per tom martins post here: https://stackoverflow.com/questions/7895335/append-data-to-a-json-file-with-php/7895384 //TODO make historical json file.. //see: https://stackoverflow.com/questions/7895335/append-data-to-a-json-file-with-php/7895384 //add something like: // $inp = file_get_contents('./latestData.json'); // $tempArray = json_decode($inp); // $tempArray[] .= $latestData; // $jsonData = json_encode($tempArray); // file_put_contents('./latestData.json', $jsonData); function makeMarker(int $id){ // generate appropriate markers based on latest JSON $readJSON = file_get_contents('./latestData.json'); //read latest data $arr = json_decode($readJSON, true); $pos = $arr[$id]["lastPos"]; // get last known position $lst = $arr[$id]["lastLocationUpdate"]; // get time of last position $rnt = $arr[$id]["isRentable"]; // check if scooter is rentable, $act = $arr[$id]["state"]; // check if scooter is ACTIVE or MAINTAINANCE // access values from the multidimensional $scooters array $nam = $arr[$id]["name"]; // get the artist name $tit = $arr[$id]["title"]; // get the works title $des = $arr[$id]["desc"]; // get the works description //check scooter status and construct marker with corresponding icon //check if scooter is rentable if($rnt == true && $act === 'ACTIVE'){ $marker = 'var scooter'.$id.' = L.marker(['.$pos.'], {time: "'.$lst.'"}).addTo(map) .bindPopup("'.$tit.'
'.$des.'
Last updated: '.$lst.'
Status: Rentable, Gallery Offline") .bindTooltip("'.$nam.'").setIcon(availableIcon);'; } elseif ($rnt == false && $act === 'ACTIVE') { $marker = 'var scooter'.$id.' = L.marker(['.$pos.'], {time: "'.$lst.'"}).addTo(map) .bindPopup("'.$tit.'
'.$des.'
Last updated: '.$lst.'
Status: Rented Out, Gallery Online") .bindTooltip("'.$nam.'").setIcon(isRentedIcon);'; }; //check if scooter is in maintenace if($act !== "ACTIVE"){ $marker = 'var scooter'.$id.' = L.marker(['.$pos.'], {time: "'.$lst.'"}).addTo(map) .bindPopup("'.$tit.'
'.$des.'
Last updated: '.$lst.'") .bindTooltip("'.$nam.'").setIcon(isMaintenanceIcon);'; }; return $marker; } //// make date time file------ ///..mmm one big one? seperate ones, timestamped ones? // 60 second update interval // make timestamp file like original python one! to check for updates // make new custom json: // scooter 1/marker time1 { lat long } // time2 { lat long } // scooter 2/marker time1 { lat long } // time2 { lat long } // // // for each // check if lastlocation is different...if update > latest file (map file..) // check if is rentable // TODO make two files // 1: current position and state of scooter, latlong, id, status // 2: historical json file, contains all scooters, updated everytime php file is loaded (or every 60 sec). No state changes, only lat long and time. even if time does not change // Custom functions function callAPI($url){ $curl = curl_init($url); curl_setopt($curl, CURLOPT_FAILONERROR, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'x-api-key: bpEUTJEBTf74oGRWxaIcW7aeZMzDDODe1yBoSxi2', 'Content-Type: application/json', )); // set the api key curl_setopt($curl, CURLOPT_USERAGENT,'ProductionRelease/3.8.2 (app.tier.sharing; build:3.8.2.0; iOS 12.4.4) Alamofire/4.9.1'); // set user-agent to that of the Tier.app, sniffed by burpsuite $result = curl_exec($curl); if(!$result){die("Connection Failure");} curl_close($curl); return $result; } ?>