Loading
Location Of - API

Location Of - API

Profile Map 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
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 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}}

Obtaining an API key

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.


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 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 Code Example
<?php{FRN}/* Load the LocationOf class */{FRN}require_once( 'locationof.php' );{FRN}/*	This loads the class that performs the interaction with the LocationOf.com server.{FRN}	You need to download this PHP file to a folder within your project to use the API.{FRN}	You can download this class file from http://www.locationof.com/api/download/{FRN}*/{FRN}{FRN}/* Initialize the API with your API key */{FRN}$api = new LocationOf( 'demo' );{FRN}/*	This creates a new LocationOf object which we will use to retrieve the wanted data.{FRN}	The constructor takes an API key as argument. Replace 'demo' with your own API key.{FRN}*/{FRN}{FRN}/* Get the actual data */{FRN}$data = $api->get();{FRN}//	Get the last location for the account from the server and store the results in $data{FRN}{FRN}//	We now have an array of location data stored in $data .{FRN}//	For demonstration purposes, we'll just print it's contents here.{FRN}print_r( $data );{FRN}?>{FRN}