Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Created March 21, 2012 17: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 aaronpk/2149881 to your computer and use it in GitHub Desktop.
Save aaronpk/2149881 to your computer and use it in GitHub Desktop.
download all geoloqi history
<?php
$oauth_token = 'YOUR ACCESS TOKEN';
$points = new StdClass;
$points->points = array(1);
$last = new StdClass;
// Set this to the date you want to start exporting data from
$last->date = '2011-01-01 00:00:00';
while(count($points->points) > 0)
{
$params['after'] = strtotime($last->date);
$params['sort'] = 'asc';
$params['count'] = '10000'; // Fetch points 10,000 at a time
$params['ignore_gaps'] = TRUE;
$httpHeader = array();
$httpHeader[] = 'Authorization: OAuth ' . $oauth_token;
$httpHeader[] = 'Timezone: ' . date('c') . ';;America/Los_Angeles';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.geoloqi.com/1/location/history?' . http_build_query($params, '', '&'));
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
echo "fetching...\r";
$response = curl_exec($ch);
$points = json_decode($response);
echo count($points->points) . ' points returned' . "\n";
if(count($points->points) > 0)
{
foreach($points->points as $i=>$p)
{
echo date('Y-m-d H:i:s', strtotime($p->date)) . "\n";
echo "\tLocation: " . $p->location->position->latitude . ",";
echo $p->location->position->longitude . "\n";
echo "\tSpeed: " . $p->location->position->speed . "\n";
echo "\tAltitude: " . $p->location->position->altitude . "\n";
echo "\tAccuracy: " . $p->location->position->horizontal_accuracy . "\n";
}
$last = $p;
}
else
{
echo "Done\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment