Capacitor-Barometer is a native plugin for Capacitor that provides access to barometric pressure sensor data on supported devices. Easily integrate real-time atmospheric pressure readings into your cross-platform mobile apps for weather tracking, altitude
npm install capacitor-barometerCapacitor-Barometer is a native plugin for Capacitor that provides access to barometric pressure sensor data on supported devices. Easily integrate real-time atmospheric pressure readings into your cross-platform mobile apps for weather tracking, altitude estimation, or scientific applications.
``bash`
npm install capacitor-barometer
npx cap sync
* isAvailable()
* start()
* stop()
* getPressure()
* echo(...)
* addListener('onPressureChange', ...)
* removeAllListeners()
* Interfaces
`typescript`
isAvailable() => Promise<{ available: boolean; }>
Checks if the barometer sensor is available on the device.
Returns: Promise<{ available: boolean; }>
--------------------
`typescript`
start() => Promise
Starts listening for barometer updates.
This will also trigger the 'onPressureChange' event.
--------------------
`typescript`
stop() => Promise
Stops listening for barometer updates.
--------------------
`typescript`
getPressure() => Promise<{ pressure: number; }>
Gets the last known pressure reading.
Ensure 'start()' has been called and data is available.
Returns: Promise<{ pressure: number; }>
--------------------
`typescript`
echo(options: { value: string; }) => Promise<{ value: string; }>
An echo method for testing.
| Param | Type |
| ------------- | ------------------------------- |
| options | { value: string; } |
Returns: Promise<{ value: string; }>
--------------------
`typescript`
addListener(eventName: 'onPressureChange', listenerFunc: (data: { pressure: number; }) => void) => Promise
Called when pressure data changes.
| Param | Type | Description |
| ------------------ | ----------------------------------------------------- | ------------------------------------------ |
| eventName | 'onPressureChange' | The name of the event ('onPressureChange') |
| listenerFunc | (data: { pressure: number; }) => void | The callback function to be executed. |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
--------------------
`typescript`
removeAllListeners() => Promise
Removes all listeners for this plugin.
--------------------
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove` | () => Promise<void> |