Interface Compass

This plugin provides access to the device's compass. The compass is a sensor that detects the direction or heading that the device is pointed, typically from the top of the device. It measures the heading in degrees from 0 to 359.99, where 0 is north.

Index

Methods

Methods

public clearWatch(id: number)

Stop watching the compass referenced by the watch ID parameter.

Parameters

  • id: number

    The ID returned by navigator.compass.watchHeading.

public getCurrentHeading(onSuccess: (heading: CompassHeading) => void, onError: (error: CompassError) => void, options?: CompassOptions)

Get the current compass heading. The compass heading is returned via a CompassHeading object using the onSuccess callback function.

Parameters

  • onSuccess: (heading: CompassHeading) => void

    Success callback that passes CompassHeading object.

  • onError: (error: CompassError) => void

    Error callback that passes CompassError object.

  • options?: CompassOptions optional

public watchHeading(onSuccess: (heading: CompassHeading) => void, onError: (error: CompassError) => void, options?: CompassOptions): number

Gets the device's current heading at a regular interval. Each time the heading is retrieved, the headingSuccess callback function is executed. The returned watch ID references the compass watch interval. The watch ID can be used with navigator.compass.clearWatch to stop watching the navigator.compass.

Parameters

  • onSuccess: (heading: CompassHeading) => void

    Success callback that passes CompassHeading object.

  • onError: (error: CompassError) => void

    Error callback that passes CompassError object.

  • options?: CompassOptions optional

    CompassOptions object

Returns

number