© 2009 OMTP Ltd. All rights reserved. OMTP and OMTP BONDI are registered trademarks of OMTP Ltd.
Location provider.
PositionSuccessCallback
PositionErrorCallback
Geolocation
Coordinates
Position
PositionError
PositionOptions
| Interface | Method |
|---|---|
| PositionSuccessCallback | void onSuccess(Position position) |
| PositionErrorCallback | void onError(PositionError error) |
| Geolocation | void getCurrentPosition(PositionSuccessCallback successCallback, PositionErrorCallback errorCallback, PositionOptions options) unsigned integer watchPosition(PositionSuccessCallback successCallback, PositionErrorCallback errorCallback, PositionOptions options) void clearWatch(unsigned short id) |
| Coordinates | |
| Position | |
| PositionError | |
| PositionOptions |
The BONDI Geolocation API is an implementation of the W3C Geolocation API. For more information about the W3C API please visit http://dev.w3.org/geo/api/.
This implementation is based on a W3C Geolocation Editor's Draft [4 May 2009].
The Geolocation API allows for the detection of the user's location by abstracting from a range of location method. For example, an implementation of the Geolocation API can be based on (A)-GPS, Wi-Fi, cell of origin (Cell-ID), IP lookups etc. or on a combination of different location methods.
The Web developer has the choice between one shot requests and watch requests, which allowing for continuous position updates. Both methods have optional parameters like timeout or maximum position age.
This is the list of URIs used to declare this API's features, for use in bondi.requestFeature. For each URL, the list of functions provided is provided.
The API allows the detection of the user's position. Since this may interfere with the user's privacy, requests to get the current position or to watch the user's position are checked for access authority.
Device capabilities: location.position
location.position
Detects the device current position
Security parameters:
origin:
Origin of the data (e.g. network, gps, wifi). The
origin is determined by the implementation
PositionSuccessCallback
Success callback for getting position information
[Callback] interface PositionSuccessCallback {
void onSuccess(in Position position);
};
Success callback that takes a Position object as input argument. It is used in the asynchronous operations to get the current position or watch position changes.
PositionErrorCallback
The geolocation API specific error callback.
[Callback] interface PositionErrorCallback {
void onError(in PositionError error);
};
This error callback defines the interface to use for all asynchronous methods of the geolocation API which use error callbacks. The callback is invoked with a PositionError object that describes the occurred error.
Geolocation
The Geolocation entry point exposed as the Geolocation modules API.
interface Geolocation {
void getCurrentPosition(in PositionSuccessCallback successCallback,
[optional] in PositionErrorCallback errorCallback,
[optional] in PositionOptions options)
raises(SecurityError, DeviceAPIError);
unsigned short watchPosition(in PositionSuccessCallback successCallback,
[optional] in PositionErrorCallback errorCallback,
[optional] in PositionOptions options)
raises(SecurityError, DeviceAPIError);
void clearWatch(in unsigned short id)
raises (DeviceAPIError);
};
This Geolocation class exposes all API functionalities such as receiving or watching the user's position.
function errorCB(err) {
alert("BONDI Geolocation API couldn't be accessed: " + err.message);
}
function successCB() {
// the Geolocation API is successfully loaded
// and can be used as described in this document
}
bondi.requestFeature(successCB, errorCB, "geolocation");
getCurrentPosition
Receiving asynchronous single shot position information.
void getCurrentPosition(PositionSuccessCallback successCallback, PositionErrorCallback errorCallback, PositionOptions options);
Requests the Geolocation API to receive the user's current position with respect to the given (if any) options.
// this function will handle each position updates
function onPositionSuccess(position) {
alert("longitude: " + position.coords.longitude + " latitude: " + position.coords.latitude);
}
// this function will handle each error in position updates
function onPositionError(error) {
alert("could not get position: " + error.code);
}
// options for the position request (e.g. setting timeout to 10s resp. 10,000ms)
var options = {};
options.timeout = 10000;
try {
// asynchronous one-shot position call - register our callbacks
bondi.geolocation.getCurrentPosition(onPositionSuccess, onPositionError, options);
}
catch(error) {
alert("could not request current position: " + error.code);
}
watchPosition
Obtaining periodic position updates.
unsigned short watchPosition(PositionSuccessCallback successCallback, PositionErrorCallback errorCallback, PositionOptions options);
Requests the Geolocation API to receive the user's current position and to continuously update the position until this watch request is deleted by using clearWatch. Optional options can be set.
// this function will handle each position update
function onPositionSuccess(position) {
alert(position.longitude);
}
// this function will handle each error in position update
function onPositionError(error) {
alert("could not get position: " + error.code);
}
var options = {};
// the subscription should return a position value within the next 10 seconds
options.timeout = 10000;
try {
// subscribe for position updates
var id = bondi.geolocation.watchPosition(onPositionSuccess, onPositionError, options);
}
catch(error) {
alert("could not request periodic position updates: " + error.code);
}
clearWatch
Stopping periodic location updates.
void clearWatch(unsigned short id);
The API is requested to stop continuously updates of an ongoing subscription.
// subscribe for position updates
var id = bondi.geolocation.watchPosition(onPositionSuccess, onPositionError, options);
// do some stuff here
...
try {
// unsubscribe for position updates
bondi.geolocation.clearWatch(id);
}
catch(error) {
alert("could not delete subscription: " + error.code);
}
Coordinates
The data type to describe a location coordinate.
interface Coordinates {
readonly attribute double latitude;
readonly attribute double longitude;
readonly attribute double altitude;
readonly attribute double accuracy;
readonly attribute double altitudeAccuracy;
readonly attribute double heading;
readonly attribute double speed;
};
A coordinate contains all data that is needed to uniquely represent the user's position.
var position = bondi.geolocation.getLastKnownPosition();
alert("latitude: " + position.coords.latitude);
[readonly]
latitude
The latitude of the current position ranging from -90° to +90° (degrees).
if(position.coords.latitude == 0) {
alert("equator");
}
[readonly]
longitude
The longitude of the current position ranging from -180° to +180° (degrees).
if(position.coords.longitude == 0) {
alert("greenwich meridian");
}
[readonly]
altitude
The altitude of the current position ranging from -90° to +90° (degrees).
if (position.coords.altitude == 0) {
alert("sea level");
}
[readonly]
accuracy
The accuracy of the position.
The longitude and latitude accuracy which is given in meters.
if (position.coords.accuracy == 2) {
alert("good accuracy");
}
[readonly]
altitudeAccuracy
The altitude accuracy of the position.
The accuracy is given in meters.
if (position.coords.altitudeAccuracy == 40) {
alert("bad altitude accuracy");
}
[readonly]
heading
The user's or device's heading.
The heading values ranges from 0° to 360° (degrees) and represents the direction in which the user is moving.
if (position.coords.heading == 90) {
alert("heading into east direction");
}
[readonly]
speed
The user's or devices' velocity.
The velocity value is given in meters per second (m/s) and represents how fast the user is moving.
if (position.coords.speed == 36) {
alert("moving with 10km/h");
}
Position
The data type, which specifies the position vector of an object.
interface Position {
readonly attribute long timestamp;
readonly attribute Coordinates coords;
};
This interface provides all information about the position and associates the coordinates with a timestamp.
[readonly]
long
timestamp
The time stamp indicating when the vector has been created.
//if (Date(position.timestamp) == Date("2008/12/12 10:00:00"))
// this if-statement is not working with real JS date object
if(position.timestamp == "123404358345") {
alert("It is the 12th December 2008 at 10 o'clock");
}
[readonly]
Coordinates
coords
The coordinates indicating where the user is located.
if (position.coords)
alert("longitude: " + location.coords.longitude);
PositionError
Generic error interface.
interface PositionError {
const unsigned short UNKNOWN_ERROR = 0;
const unsigned short POSITION_UNAVAILABLE_ERROR = 2;
const unsigned short TIMEOUT_ERROR = 3;
readonly attribute unsigned short code;
readonly attribute DOMString message;
};
[readonly]
unsigned
short
code
The error code of this error event.
// the onEvent method of the ErrorCallback
function onEvent(error) {
// react if the error was raise because of a timeout
if(error.code == PositionError.TIMEOUT_ERROR)
alert("cannot provide location in the given time");
}
[readonly]
DOMString
message
A description of the error.
// the onEvent method of the ErrorCallback
function onEvent(error) {
// print out the error message
alert("Error " + error.code + ": " + error.message );
}
PositionOptions
Definition of options that can be used for location requests.
interface PositionOptions {
attribute long timeout;
attribute long maximumAge;
attribute boolean enableHighAccuracy;
};
Position requests can be enriched with options to influence the quality reponse time of the location provider.
// this function will handle each position update
function onPositionSuccess(position) {
alert(position.longitude);
}
// this function will handle each error in position update
function onPositionError(error) {
alert("could not get position: " + error.code);
}
var options = {};
// the subscription should return a position value within the next 10 seconds
options.timeout = 30000;
bondi.geolocation.watchPosition(successCallback, errorCallback, options);
long
timeout
Specification of a timeout value in milliseconds.
After the timeout interval has elapsed an error is thrown in order to inform all requesting/subscribed applications about the unavailability of position data. The default value is -1 which is interpreted as no timeout. i.e., a PositionError.code = PositionError.TIMEOUT is never thrown if no timeout is set or the timeout is set to -1.
var successCallback = {};
var errorCallback = {};
var options = {};
// the subscription should return a position value within the next 10 seconds
options.timeout = 10000;
// subscribe for position updates
var subscription = bondi.geolocation.watchPosition(successCallback, errorCallback, options);
long
maximumAge
Specification of the maximum age of position data.
This value is given in milliseconds. If the time since the last position data was recorded exceeds the maximumAgean error is thrown to inform all involved applications. The default value is 0 which means that no cached data is used and a new location must be acquired.
var successCallback = {};
var errorCallback = {};
var options = {};
// the subscription should return a position not older then 10 seconds
options.maximumAge = 10000;
// subscribe for position updates
var subscription = bondi.geolocation.watchPosition(successCallback, errorCallback, options);
boolean
enableHighAccuracy
The demand for high/best-effort accuracy.
For high accuracy the accuracy parameter must be set to true.
When set indicates that a high accuracy for positioning is required even if it is at the expense of higher power consumption or slower response time. The default is false.
var successCallback = {};
var errorCallback = {};
var options = {};
// the subscription should return a very accurate position without saving any power
options.enableHighAccuracy = true;
// subscribe for position updates
var subscription = bondi.geolocation.watchPosition(successCallback, errorCallback, options);