Created
August 6, 2011 19:01
-
-
Save geoloqi/1129641 to your computer and use it in GitHub Desktop.
Example code for posting a location update to the Geoloqi API
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 | |
// Get a permanent access token from the developers website https://developers.geoloqi.com/getting-started | |
$permanentToken = ''; | |
$timestamp = time(); | |
$latitude = 45.524; | |
$longitude = -122.6843; | |
$speed = 0; | |
$altitude = 0; | |
$hacc = 100; | |
// Build an array of location updates. You can include more than one location fix | |
// in a single request to the Geoloqi API. | |
// | |
// Full API docs are here: | |
// https://developers.geoloqi.com/api/location/update | |
$data[] = array( | |
'date' => date('c', $timestamp), // date('c') formats in ISO8601 standard | |
'location' => array( | |
'position' => array( | |
'latitude' => $latitude, | |
'longitude' => $longitude, | |
'speed' => $speed, // km/h | |
'altitude' => $altitude, // meters | |
'horizontal_accuracy' => $hacc // meters | |
), | |
'type' => 'point' | |
), | |
'client' => array( | |
'name' => 'PHP-CLI', // change to your app name | |
'version' => 0.1, | |
'platform' => '', // 1 or 2-word description of your software | |
'hardware' => '' // 1 or 2-word description of your hardware | |
) | |
); | |
$ch = curl_init('https://api.geoloqi.com/1/location/update'); | |
curl_setopt($ch, CURLOPT_POST, TRUE); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Authorization: OAuth ' . $permanentToken, // Include your access token | |
'Content-type: application/json' // Set content-type to JSON | |
)); | |
$response = curl_exec($ch); | |
print_r(json_decode($response)); | |
echo "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment