Skip to content

Instantly share code, notes, and snippets.

@m4p
Created July 14, 2013 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4p/5993873 to your computer and use it in GitHub Desktop.
Save m4p/5993873 to your computer and use it in GitHub Desktop.
Backend for map.af/api.location
#!/usr/bin/php
<?PHP
require '/var/www/offsite/class.sosumi.php';
header('Content-Type: application/json');
$file = '/var/www/offsite/location.cache';
if (time() - filemtime($file) > 5*60) {
// older than cache limit
$ssm = new Sosumi('your_username', 'your_password');
$loc = $ssm->locate(5); //Devicenumber found by try&error
if(strlen($loc['latitude']))
{
$json = "{\"latitude\":\"".$loc['latitude']. "\", \"longitude\":\"" . $loc['longitude'] . "\", \"accuracy\":\"" . $loc['accuracy'] . "\", \"timestamp\":\"" . $loc['timestamp'] . "\", \"serverepoch\":\"" . date("U") . "\"}";
print($json);
file_put_contents($file, $json);
}
} else {
print(file_get_contents($file));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment