Skip to content

Instantly share code, notes, and snippets.

@unwiredlabs
Last active December 20, 2015 05:49
Show Gist options
  • Save unwiredlabs/6081433 to your computer and use it in GitHub Desktop.
Save unwiredlabs/6081433 to your computer and use it in GitHub Desktop.
This script is a demo on how to use LocationAPI.org's Mobile Triangulation API v1.
<?php
/*
* Sample script to test Unwired Labs API v1 - DEPRECATED
*
* Created: 20th July, 2013
* Author: Unwired Labs
*
*/
//URL of our API
$url = "http://us1.unwiredlabs.com/process.php"; //defined in includes.php
//Parameters to pass. Replace with your token and your cell tower data
$qry_str = "?token=your_token&mcc=310&mnc=410&lac=7033&cid=17811";
//Initialize cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . $qry_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '3');
$response = trim(curl_exec($ch));
if (curl_errno($ch)) {
exit(curl_error($ch));
}
curl_close($ch);
$response = substr($response, strpos($response, "{"));
$data = json_decode($response, true); //converts response into array
//If there wasn't a "status" array key, something's wrong with the response
if (!isset($data['status']))
exit("Uh oh, it didn't work well. Is the API url correct?");
//If it returned an error message, exit & print the error
if ($data['status'] != "ok")
exit("Whoops, there was an error: '{$data['message']}'");
//Everything's fine so far, so print the latitude & longitude.
echo "Lat: " . strval($data['lat']) . " Lon: " . strval($data['lon']);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment