Scandit.Geolocation

Classes

PositionWatcher

Methods

(static) getPosition(options?: object): Promise

Retrieves current position

Parameters:
Name Type Attributes Description
options object <optional>
Properties
Name Type Attributes Default Description
highAccuracy boolean <optional>
false

Enables best possible accuracy.

timeout boolean <optional>
10000

Timeout in milliseconds to wait for a result, return an error if triggered.

Returns:
Promise

Promise which is resolved to Scandit.Geolocation.Position.

Can return an error with code:

Examples
Get the current position of the device
  • JavaScript
  • ES6
Scandit.Geolocation.getPosition().then(function(position) {
  console.log('Current position is: ' + position.latitude + ', ' + position.longitude);
});
Scandit.Geolocation.getPosition().then(position => {
  console.log(`Current position is: ${position.latitude}, ${position.longitude}`);
});

(static) watch(successCallback: function, errorCallback: function, options?: object): Scandit.Geolocation.PositionWatcher

Watches for location changes

Parameters:
Name Type Attributes Description
successCallback function

Callback for location update. Callback will be called with Scandit.Geolocation.Position instance.

errorCallback function

Callback for error

options object <optional>
Properties
Name Type Attributes Default Description
highAccuracy boolean <optional>
false

Enables best possible accuracy.

Returns:
Examples
Watching for location changes
  • JavaScript
  • ES6
var positionWatcher = Scandit.Geolocation.watch(function(position) {
  console.log('Location changed, new location is: ' + position.latitude + ', ' + position.longitude);
}, function(reason) {
  console.log('Something went wrong, reason: ' + reason);
}, {highAccuracy: true});
let positionWatcher = Scandit.Geolocation.watch(position => {
  console.log(`Location changed, new location is: ${position.latitude}, ${position.longitude}`);
}, reason => {
  console.log(`Something went wrong, reason: ${reason}`);
}, {highAccuracy: true});

Type Definitions

Position

Properties:
Name Type Description
latitude double

Latitude

longitude double

Longitude

altitude double

Altitude

accuracy double

Estimated accuracy of the location, in meters

altitudeAccuracy double

Estimated altitude accuracy of the location, in meters

heading double

Heading direction

speed double

Speed, in m/s

timestamp integer

Exact time the position was recorded