Filename | Description | Modification date |
locationof.php | API Helper Class Make sure to keep this file up to date in your project! | {{1496581323 | datetimeformat}} |
demopage.php | Example: Static Map | {{1428669203 | datetimeformat}} |
demopagehour.php | Example: Map showing last hour | {{1428669192 | datetimeformat}} |
ajaxed.php | Example: Map showing last hour with auto update | {{1437298580 | datetimeformat}} |
ajaxedsimple.php | Example: Map showing last hour with auto update (simple) | {{1510500017 | datetimeformat}} |
distance.php | Example: Calculate distance to various points and return closest | {{1428669212 | datetimeformat}} |
You can get an API key from the 'API' tab on your profile, once you are logged in.
You may use key 'demo' for examplary results.
To use the API as a consumer you need a Consumer or Business license.
You may execute a database poll once every fifteen (15) seconds, with a maximum of 6000 requests per day.
The provided PHP class supports a method of (flatfile) caching to keep within bounds of this limit.
Exceeding this limit for extended periods of time will cause the API key to be suspended automatically.
public class LocationOf ( Download PHP class )
An object that handles retrieval of data from the LocationOf.com servers.
Data will be returned as an associative array as described below in the method summary.
Each LocationOf
object represents a unique API key.
Dependencies
- cURL
Comments
The class will cache retrieved data on disk in a folder in the same directory where the class file is stored. The default folder is called LocationOf_cache
. Make sure the class has permission to create this folder or create the folder manually. Also make sure the class has write permissions for the cache folder. If the folder does not exist and cannot be created, or, if the folder does exist but the class has insufficient permissions to write inside the folder, caching will not work.
Constructor Summary |
LocationOf() Creates a new LocationOf object using 'demo' as API key. |
LocationOf(String api_key) Creates a new LocationOf object using the given API key. You can get an API key from the 'API Access' tab on your profile, once you are logged in. |
Method Summary | |
Array | get() Returns the last known location for the account. |
Array | get(int seconds) Returns the last seconds worth of locations for the account.seconds must be lower than 604800. |
Array | get(int timestampStart, int timestampEnd) Returns any locations between timestampStart and timestampEnd for the account.timestampStart and timestampEnd should be valid integer unix timestamps (seconds passed since 01 Jan 1970).timestampEnd must be higher than timestampStart and (timestampEnd - timestampStart) must be lower than 604800. |
void | setUseCache(boolean enabled) Enable or disable caching of retrieved results. If enabled, the results will be written to a flatfile and will only be updated once 15 seconds have passed since last retrieval. Must be called before calling get to take effect.Default is true . |
<?php /* Load the LocationOf class */ require_once( 'locationof.php' ); /* This loads the class that performs the interaction with the LocationOf.com server. You need to download this PHP file to a folder within your project to use the API. You can download this class file from http://www.locationof.com/api/download/ */ /* Initialize the API with your API key */ $api = new LocationOf( 'demo' ); /* This creates a new LocationOf object which we will use to retrieve the wanted data. The constructor takes an API key as argument. Replace 'demo' with your own API key. */ /* Get the actual data */ $data = $api->get(); // Get the last location for the account from the server and store the results in $data // We now have an array of location data stored in $data . // For demonstration purposes, we'll just print it's contents here. print_r( $data ); ?>