Skip to content

Instantly share code, notes, and snippets.

@noestreich
Last active December 16, 2015 11:18
Show Gist options
  • Save noestreich/5426333 to your computer and use it in GitHub Desktop.
Save noestreich/5426333 to your computer and use it in GitHub Desktop.
Snippet for Panic's iPad App "Statusboard" to show available Drive Now cars in Berlin within a predefined radius. i.e: How many free cars are within 300m from my home-address? Screenshot: http://i.imgur.com/zjvq1Ev.jpg
<?php
##config for homelocation and radius (in meter)
$myhomelat = "52.49993";
$myhomelng = "13.39190";
$myradius = "300";
## get the drive now json
$driveURL = "https://www.drive-now.com/php/metropolis/json.vehicle_filter?cit=6099";
$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);
#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++;
}
}
?>
<!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="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;
}
</style>
</head>
<body onload="init()">
<div id="main">
<span class="number"><?php echo $i;?></span><img style="margin-left:40px;margin-top:10px;" src="http://i.imgur.com/UdodyNU.png">
</div><!-- main -->
</body>
</html>
@orienterare
Copy link

Updated Gist for DriveNow and Car2Go vehicles (in Hamburg):
https://gist.github.com/orienterare/a87b163d183bb43c9a60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment