Skip to content

Instantly share code, notes, and snippets.

@geoloqi
Created August 6, 2011 19:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geoloqi/1129641 to your computer and use it in GitHub Desktop.
Save geoloqi/1129641 to your computer and use it in GitHub Desktop.
Example code for posting a location update to the Geoloqi API
<?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