Skip to content

Instantly share code, notes, and snippets.

@dwhacks
Created October 25, 2016 19:16
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 dwhacks/c8cb7d7094fe06c4e1be405e0885cec3 to your computer and use it in GitHub Desktop.
Save dwhacks/c8cb7d7094fe06c4e1be405e0885cec3 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php if(!session_id()) session_start(); ?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>GPS Tracker</title>
</head>
<body>
TESTING
<?php
# particle-map.php
// GPS UNIT
// https://cdn.sparkfun.com/datasheets/GPS/GP-20U7.pdf
$deviceID = "MY DEVICE ID";
$access_token = "MY ACCESS TOKEN";
$url = "https://api.particle.io/v1/devices/$deviceID/";
$formed_url ='?access_token='.$access_token;
$variable_name = "STU";
$headers = array(
"GET /v1/devices/".$variable_name.$formed_url." HTTP/1.1",
"Host: api.particle.io");
// setup and make HTTP GET REQUEST
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url.$variable_name.$formed_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return output
$retrievedhtml = curl_exec ($ch);
curl_close($ch);
$json = json_decode($retrievedhtml,true);
// see if there was an error connecting with electron
if ($json['error'] != "") {
echo ("ERROR = " . $json['error'] . "<br>");
} else {
// read the data into a variable
$DATA = $json['result'];
// output to screen
echo ("<b>result: </b>" . $DATA . "<br>");
// split data into array is comma delimited
$pieces = explode(",", $DATA);
// A = valid, V = not valid
$status = $pieces[2];
if ($status == "V") {
echo ("Data not valid<br>Can the GPS unit see the sky?");
} else {
// put data in variables
$LAT = $pieces[3];
$LON = $pieces[5];
$EW = $pieces[6];
// Convert LAT
$deg = substr($LAT, 0, 2);
$min = substr($LAT, 2, 8);
$sec = '';
$resultLAT = $deg+((($min*60)+($sec))/3600);
print ("Latitude " . $resultLAT . "<br>");
// Convert Longitude
$deg = substr($LON, 0, 3);
$min = substr($LON, 3, 8);
$sec='';
$resultLON = $deg+((($min*60)+($sec))/3600);
// Is it East or West
if ($EW == "W") {
$resultLON = $resultLON * -1;
}
print ("Longitude " . $resultLON . "<br>");
}
}
?>
<iframe
width="600"
height="450"
frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?key=GOOGLE API KEY
&q=<?=$resultLAT?>,<?=$resultLON?>" allowfullscreen>
</iframe>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment