Location Of - API

Profile Map Premium Helpdesk Log Out

The Location Of API allows websites and programs to integrate with Location Of, enabling users to read their current location, their location history, and more!

Using the Location Of API, you can directly retrieve a device's last known location(s) from the database.
This allows you to build your own project or website that incorporates geodata directly from your phone.
Access to the API is locked by a private key, and therefore allows retrieval of data from your account even when it has been set to Private mode.


Examples
Download source code
A map that displays the most recent location.
Download source code
A map that displays the last hour of tracks.
Download source code
A map that displays the last hour of tracks and automatically updates every 15 seconds.
Download source code
An example that calculates the distance of the user to several points, and returns the closest one in text format.


Changelog
Filename Description Modification date
locationof.php API Core Make sure to keep this file up to date in your project! {{1469109642 | 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) {{1437298607 | datetimeformat}}
distance.php Example: Calculate distance to various points and return closest {{1428669212 | datetimeformat}}

Obtaining an API key

You can get an API key from the 'API Access' 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 Premium license; Businesses are required to use a Pro license.


Limitations

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.


Class LocationOf

public class LocationOf ( Download PHP class )

An object that handles the 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 time_start, int time_end)
          Returns any locations between time_start and time_end for the account.

          time_start and time_end should be valid integer unix timestamps (seconds passed since 01 Jan 1970).

          time_end must be higher than time_start and (time_end - time_start) must be lower than 604800.
void setCacheEnabled(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 Code Example
<?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 );
?>