-
-
Save orienterare/a87b163d183bb43c9a60 to your computer and use it in GitHub Desktop.
Script showing free DriveNow and Car2Go vehicles in Hamburg in a specified vicinity for Panic Status Board
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
##config for homelocation and radius (in meter) | |
$myhomelat = "53.554340"; | |
$myhomelng = "9.988971"; | |
$myradius = "400"; | |
## get the drive now json | |
$driveURL = "https://www.drive-now.com/php/metropolis/json.vehicle_filter?cit=40065"; | |
$process = curl_init($driveURL); | |
curl_setopt($process, CURLOPT_HEADER, false); | |
curl_setopt($process, CURLOPT_RETURNTRANSFER, true); | |
$data = json_decode(curl_exec($process), true); | |
curl_close($process); | |
## get car2go | |
$car2goURL = "https://www.car2go.com/api/v2.1/vehicles?loc=hamburg&oauth_consumer_key=car2gowebsite&format=json"; | |
$process = curl_init($car2goURL); | |
curl_setopt($process, CURLOPT_HEADER, false); | |
curl_setopt($process, CURLOPT_RETURNTRANSFER, true); | |
$data_car2go = json_decode(curl_exec($process), true); | |
curl_close($process); | |
#function to check, radius-distance from car-location to home-location | |
#from http://techhasnoboundary.blogspot.de/2011/10/check-if-gps-location-latitude-and.html | |
function isInArea($homeloclat, $homeloclng, $loclat, $loclng){ | |
$R = 6371; | |
$lat1 = $loclat; | |
$lon1 = $loclng; | |
$lat2 = $homeloclat; | |
$lon2 = $homeloclng; | |
$dLat = ($lat2 - $lat1) * M_PI / 180; | |
$dLon = ($lon2 - $lon1) * M_PI / 180; | |
$a = sin($dLat / 2) * sin($dLat / 2) + cos($lat1 * M_PI / 180) * cos($lat2 * M_PI / 180) * sin($dLon / 2) * sin($dLon / 2); | |
$c = 2 * atan2(sqrt($a), sqrt(1 - $a)); | |
$d = $R * $c; | |
$result = $d * 1000; | |
return ($result); | |
} | |
#get the cars | |
$autos = $data['rec']['vehicles']['vehicles']; | |
$i = 0; | |
# search through json, count cars within location | |
foreach ($autos as $mydata){ | |
if ((isInArea($myhomelat, $myhomelng, $mydata['position']['latitude'], $mydata['position']['longitude']) <= $myradius) && ($mydata['address'] != 'Umrüster DE') ){ | |
//debug | |
//echo $mydata['carName']; | |
//echo "<br>"; | |
//echo $mydata['address']; | |
$i++; | |
} | |
} | |
$car2go = $data_car2go['placemarks']; | |
$j = 0; | |
# search through json, count cars within location | |
foreach ($car2go as $mydata){ | |
# var_dump($mydata); | |
if ((isInArea($myhomelat, $myhomelng, $mydata['coordinates'][1], $mydata['coordinates'][0]) <= $myradius) ){ | |
//debug | |
#echo $mydata['name']; | |
#echo "<br>"; | |
#echo $mydata['address']; | |
$j++; | |
} | |
} | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<meta http-equiv="refresh" content="180"> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf8" /> | |
<meta http-equiv="Cache-control" content="no-cache" /> | |
<style type="text/css"> | |
@font-face | |
{ | |
font-family: "Roadgeek2005SeriesD"; | |
src: url("http://panic.com/fonts/Roadgeek 2005 Series D/Roadgeek 2005 Series D.otf"); | |
} | |
body, * | |
{ | |
} | |
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td | |
{ | |
margin: 0; | |
padding: 0; | |
} | |
fieldset,img | |
{ | |
border: 0; | |
} | |
/* Settin' up the page */ | |
html, body, #main | |
{ | |
overflow: hidden; /* */ | |
} | |
body | |
{ | |
color: white; | |
font-family: 'Roadgeek2005SeriesD', sans-serif; | |
font-size: 20px; | |
line-height: 24px; | |
} | |
body, html, #main | |
{ | |
background: transparent !important; | |
} | |
.number | |
{ | |
font-size: 140px; | |
line-height: 120px; | |
margin-left: 20px; | |
margin-top: 5px; | |
color: white; | |
text-shadow:0px -2px 0px black; | |
text-transform: uppercase; | |
} | |
.item { | |
display:block; | |
} | |
</style> | |
</head> | |
<body onload="init()"> | |
<div id="main"> | |
<div class="item"> | |
<span class="number"><?php echo $i;?></span><img style="margin-left:40px;margin-top:10px;" src="http://i.imgur.com/UdodyNU.png"> | |
</div> | |
<div class="item"> | |
<span class="number"><?php echo $j;?></span><img style="margin-left:40px;margin-top:10px;" src="http://i.imgur.com/ItXPXH9.jpg" width="100"> | |
</div> | |
</div><!-- main --> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment