1.1.4 • Published 1 year ago
react-world-compass v1.1.4
React World Compass
The react package is to provide a useCompass function to obtain the absolute orientation of the device. The package use the device event deviceorientationabsolute for Chrome/Edge in Android and webkitCompassHeading for Safari in iOS. Sorry to Firefox.
Installation
yarn add react-world-compassor
npm install react-world-compassUsage
import useCompass, { requestPermission, isSafari } from "react-world-compass"useCompass is a React Hook that lets you obtain the real time degree absolute to the North.
function MyComponent() {
const degree = useCompass(interval)
// ...
}For the Safari in iOS, you should call requestPermission through a user event, e.g., clicking a button box, before using useCompass.
Paramenter
interval: The interval you want to capture the compass value. Type:number, default:20(i.e., 20ms)
Returns
useCompass() returns the degree absolute to the North, (i.e., 90 for East, 180 for South, and 270 for West). If the device not support such feature, null value will be returned.
License
MIT License