npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zero-degree

v3.1.6

Published

A module that constantly monitors and returns the direction angle of the target location as the phone rotates or moves. This is a React Native/Expo package.

Downloads

60

Readme

Zero Degree

(React Native/Expo package)

A module that constantly monitors and returns the direction angle of the target location as the phone rotates or moves. This is a React Native/Expo package.

(For Github users: NPM package link - https://www.npmjs.com/package/zero-degree)

What It Does

* Monitors device location (GPS) and device heading (using magnetometer sensor).
* Constantly returns angle (in degree) between the device and the target.
* The value returns from the module is from -179 to 180 degree; 0 degree means the device is pointed to the target perfectly.
* It returns the degree value accurately even the phone is on hand and tilted, i.e. not perfectly horizontal.

How To Use

import ZeroDegree from 'zero-degree';

let _Mecca = { latitude: 21.42287137530198, longitude: 39.82573402862004 };
let zeroDegree = new ZeroDegree(_Mecca);
zeroDegree.watchAsync(degree => console.log(degree));

Use with useEffect/useState in projects. See the Complete Example below this readme or check out the demo: https://snack.expo.io/@tareqshahriar/zero_degree

You can run the demo on a real device. Install Expo Go app (iOS app / Android app); on mobile browser, tap the demo link, it will be prompted to open the demo using Expo Go.

Events, Props etc

Constructor parameter: Pass an Json object containing latitude, longitude of the target location.

const _Greenland = { latitude: 76.94606201163724, longitude: -43.474120688453034 };
let zeroDegreeObj = new ZeroDegree(_Greenland);

zeroDegreeObj.watch(onDegreeUpdate, onError): Instance method, to start watching the device location and device heading.

onDegreeUpdate callback: Constantly receives the degree value of the phone heading with respect to target as the phone moves.

await zeroDegreeObj.watchAsync(degree => console.log(degree));

onError callback: It will be called whenever a error will be occurred, with an object as argument having error details.

zeroDegreeObj.watchAsync(
   degree => console.log(degree), 
   errData => console.error(errData);
);

zeroDegreeObj._getLogData: For debugging purpose. Assign a function to it to receive additional data in an object.

zeroDegreeObj._getLogData = log => console.log(log);

A Complete Example

// App.js
import React, { useState, useEffect } from 'react';
import { Text, View } from 'react-native';
import ZeroDegree from 'zero-degree';

let _Mecca = { latitude: 21.42287137530198, longitude: 39.82573402862004 };

export default function App() {
   const [degree, setDegree] = useState(null);
   const [err, setError] = useState(null);
   const [log, setLog] = useState(null);

  useEffect(() => {
    let zeroDegree;
    async function initZeroDegree() {
      zeroDegree = new ZeroDegree(_Mecca);  
      zeroDegree._getLogData = log => setLog(log); // optional

      await zeroDegree.watchAsync(degree => setDegree(Math.round(degree)),
        err => setError(err));
    }

    initZeroDegree();

    return () => zeroDegree.unwatch();
   }, []);

  return (
    <View>
      <Text>Target: {degree}&deg;</Text>
      <Text>Info: {JSON.stringify(log)}</Text>
      <Text>Error: {JSON.stringify(err)}</Text>
    </View>
  );
}

Accuracy Tests

Device: IPhone 7
Location: Dhaka, Bangladesh

| Targets | Result | | --------|--------| | Mecca, Saudi Arabia | OK | | Greenland (north pole) | OK | | Exact north (Yeniseysky, Russia) | OK | | Exact south (Indian Ocean) | OK | | Exact west (Algeria) | OK | | Exact east (North Pacific Ocean) | OK | | New Zealand | OK | | Antarctica (south pole) | OK | | Nunavut, Canada | OK |

To perform a reverse test, different locations were passed to the module as device's location, ignoring the GPS data.

Target: Mecca, Saudi Arabia

| Device location | Result | | ---------------- | ------ | | Melbourne, Australia | OK | | Greenland (north pole) | OK* | | Indian Ocean (exact south of Mecca) | OK | | Barents Sea (exact north of Mecca | OK | | Timaukel, Magallanes and Chilean Antarctica, Chile | OK | | South China Sea (exact east of Mecca) | OK | | Antarctic Ice shield, Antarctica | Seems OK* |

[*] On earth globe, Antarctic Ice shield (-75.36047491435592, -79.42558210228636) is located at south pole which is under the the globe. As a mocked location, it produces good result, but in real, magnetometer will not work on south pole as well as on north pole.