PHP code example of travisamiller / spot-tracker-api
1. Go to this page and download the library: Download travisamiller/spot-tracker-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
travisamiller / spot-tracker-api example snippets
use TravisAMiller\SpotTrackerApi\ApiClient;
$client = new ApiClient('your-feed-id-here');
$result = $client->latest();
$result->getFeed(); // Details about data feed.
$result->getMessages(); // Array of all messages received -- only one for this endpoint.
$result->getMessage(); // Direct accesss to message recevied from this endpoint.
use TravisAMiller\SpotTrackerApi\ApiClient;
$client = new ApiClient('your-feed-id-here');
// retrieve messages on the first page of results, any date range.
$result = $client->messages();
// retrieve messages on the second page of results.
$result = $client->messages([
'start' => 50
]);
// only retrieve messages newer than midnight yesterday.
$result = $client->messages([
'startDate' => new DateTime('yesterday midnight')
]);
// only retrieve messages since older than midnight today.
$result = $client->messages([
'endDate' => new DateTime('today midnight')
]);
// retrieve message from yesterday on the third page.
$result = $client->messages([
'start' => 100, // 0 = first age, 50 = second page, 100 = third page
'startDate' => new DateTime('yesterday midnight'),
'endDate' => new DateTime('today midnight')
]);
use TravisAMiller\SpotTrackerApi\ApiClient;
$client = new ApiClient('your-feed-id-here');
$result = $client->messages([
'start' => 50
]);
$result->hasNextPage(); // true if there are more than 100 results.
$result->hasPreviousPage() // true if there the current position isn't the first page.
$request = $result->getNextPageRequest(); // get request for next page of results.
$request = $result->getPreviousPageRequest(); // get request for last page of results.
$result = $client->send($request); // gets results for either request above.
use TravisAMiller\SpotTrackerApi\ApiClient;
$client = new ApiClient('your-feed-id-here');
$page = $client->messages();
do {
if ($page->hasErrors()) {
foreach($page->getErrors() as $error) {
printf(
"Error: %s (%s)",
$error->getDescription(),
$error->getCode()
);
}
break;
}
foreach ($page->getMessages() as $message) {
printf(
"Location: %F %F (ID: %d)\n",
$message->getLatitude(),
$message->getLongitude(),
$message->getId()
);
}
} while (
$page->hasNextPage() &&
$page = $client->send($page->getNextPageRequest())
);
$result = $client->messages([
'start' => 50
]);
$yesterday = new MessagesFilter([
'startDate' => new DateTime("yesterday midnight"),
'endDate' => new DateTime("today midnight"),
]);
$results = $client->messages($yesterday);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.