/
TrackDeviceLastLocationHistory.php
70 lines (55 loc) · 2.06 KB
/
TrackDeviceLastLocationHistory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Route4Me;
$root = realpath(dirname(__FILE__).'/../../');
require $root.'/vendor/autoload.php';
use Route4Me\Enum\DeviceType;
use Route4Me\Enum\Format;
use Route4Me\Tracking\Track;
use Route4Me\Tracking\TrackSetParams;
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_BAIL, 1);
// Set the api key in the Route4me class
// This example not available for demo API key
Route4Me::setApiKey(Constants::API_KEY);
// Get a random route ID
$route = new Route();
$routeId = $route->getRandomRouteId(0, 20);
assert(!is_null($routeId), "Cannot retrieve a random route ID");
echo "routeId -> $routeId <br><br>";
// Set GPS postion to the selected route
// Set right member_id corresponding to the API key
$params = TrackSetParams::fromArray([
'format' => Format::SERIALIZED,
'route_id' => $routeId,
'member_id' => 105323,
'course' => 3,
'speed' => 100,
'lat' => 41.8927521,
'lng' => -109.0803888,
'device_type' => DeviceType::IPHONE,
'device_guid' => 'qweqweqwe',
'device_timestamp' => date('Y-m-d H:i:s'),
]);
$status = Track::set($params);
assert(!is_null($status), "Cannot send GPS position to the selected route");
assert(isset($status['status']), "Cannot send GPS position to the selected route");
assert($status['status'], "Cannot send GPS position to the selected route");
if (!$status) {
echo 'Setting of GPS position failed';
return;
}
$params = [
'route_id' => $routeId,
'device_tracking_history' => '1',
];
$result = $route->GetLastLocation($params);
if (isset($result->tracking_history)) {
foreach ($result->tracking_history as $history) {
echo 'Speed --> '.$history['s'].'<br>';
echo 'course --> '.$history['d'].'<br>';
echo 'Timestamp --> '.$history['ts_friendly'].'<br>';
echo 'Latitude --> '.$history['lt'].'<br>';
echo 'Longitude --> '.$history['lg'].'<br>';
echo '========================================<br><br>';
}
}