firofame / react-native-compass-heading Goto Github PK
View Code? Open in Web Editor NEWReact Native module for iOS & Android to receive compass heading
Home Page: https://www.npmjs.com/package/react-native-compass-heading
License: MIT License
React Native module for iOS & Android to receive compass heading
Home Page: https://www.npmjs.com/package/react-native-compass-heading
License: MIT License
I followed the installation instructions and I've got undefined for both heading and accuracy, while testing in emulator.
This is the code I am using and the logs says undefined:
`
import React, { useState, useEffect } from "react"
import { Image, StyleSheet } from "react-native"
import CompassHeading from "react-native-compass-heading"
function Compass() {
const [compassHeading, setCompassHeading] = useState(0)
useEffect(() => {
const degree_update_rate = 3
// accuracy on android will be hardcoded to 1
// since the value is not available.
// For iOS, it is in degrees
CompassHeading.start(degree_update_rate, ({ heading, accuracy }) => {
console.log({heading, accuracy})
setCompassHeading(heading)
})
return () => {
CompassHeading.stop()
}
}, [])
if(!compassHeading) return null
return (
<Image
style={[
styles.image,
{ transform: [{ rotate: `${360 - compassHeading}deg` }] },
]}
resizeMode="contain"
source={require("../compass.png")}
/>
)}
const styles = StyleSheet.create({
image: {
width: "90%",
flex: 1,
alignSelf: "center",
},
})
export default Compass
`
Hi,
Using the 1.5.0 version of the package, my editor can't find the type declaration file. According to the package.json, it should be at the root of the project, but no file is here. Instead, a declaration file is created inside the lib/typescript directory (with just any as type).
I'd be glad to help if you can give me some information about the build system.
Version 1.4.2 is fine, by the way (see it in npm)
Hi,
I contact you because i wanna use a compass in my ios application.
And when I tried your example, it works perfectly on android, but I can't get it to work on ios.
If you have any advice.
Thanks in advance, best regards
I used this to build a compass specifically for mapping tower locations and providing feedback on how to best directionally tune your antenna ... on iOS it works great (apple maps), however on android it doesn't work very well (google maps) ... if i open google maps and verify that it's tracking heading correctly it's fine, so i know it's not an issue with the device.
Its lagging a lot for me..can u help?
Hi, thank you for releasing this package! I'm trying to use it but when I start the app it doesn't load. In Xcode it says:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error when sending event: HeadingUpdated with body: 323.4593505859375. Bridge is not set. This is probably because you've explicitly synthesized the bridge in CompassHeading, even though it's inherited from RCTEventEmitter.'
I'm using it in my main app.js
on componentDidMount
and without hooks (React Native 0.59.3). Any ideas? Thanks!
dear developer
I can't do "npx pod-install" on linux
any solution?
It's working fine on iOS but on on Android I'm getting the error below and can't build the project
A problem occurred configuring project ':react-native-compass-heading'.
> compileSdkVersion is not specified. Please add it to build.gradle
* What went wrong:
A problem occurred evaluating project ':react-native-compass-heading'.
> Plugin with id 'maven' not found.
I like this package, exactly what I was looking for! Lightweight, simple compass. But I notice if I am using, rotate my phone for a few seconds (like when walking) then pause, then move phone again my true north changes where it is pointing. So it is perfect initially but on pause, I am not sure what happens but loses true north.
My Android Phone Test: (against a real compass in my hand)
In my test, I lay the phone flat in palm (right angle) pointing away from my body. True north is correct.
I slowly reverse the phone so it is facing my body (180' turn), still at a right angle. True north is off by 90' or so.
When I continue clockwise to finish my 360 circle and put phone back in original position it slowly gets closer and when I get fully back to where I started, true north is correct.
How to use this liabrary? there is no examle and as well as very less explain how to use it in project.
For some uknown issue, I'm still reciving on iOS -1 heading.
react-native-geolocation-service shows same, until I don't move around a little bit, after it shows single value, probably there is some kind of limit for retriving info, this package doesn't change even after moving
By any chance somebody faced this issue ? Or it's something new?
I want to make a 3d compass in android. Is there any way to do this with this library? Or Can anyone help me how I can proceed to 3d compass
Is it by design that up and down movement (z changes) orientation changes also the compass value? Or is it just a bug with React Native 0.64.0? Thanks.
After importing and using this function as in the example, my device shows this message: 'CompassHeading: undefined undefined'.
It seems to be responding to rotation of the device but I can't resolve this issue. I tried giving more permisions but that didn't resolve the issue.
Does anyone know the fix?
When testing on a simulator or on a device without sensors, the start call still succeeds. Any way to detect sensors?
Why is this package so similar to https://github.com/vnil/react-native-simple-compass ?
I added the library to my project and it works perfectly on android, but when trying to run it on iOS Simulator through Xcode it shows this error: 'Corelocation/CoreLocation.h' file not found
Has anyone ever experienced this? Did I forget something?
Try in:
iOS 16.2
Xcode 14.2
RN 0.71.0
Error: The package 'react-native-compass-heading' doesn't seem to be linked. Make sure:
I am using react native cli
When u leave the compass page then go back in, if your device is stable on a surface for example, the compass either freezes or takes time to calculate the degree, anyone faced this issue and fixed it?
Nowadays accuracy in Android is pseudo constant 1. At least this (https://stackoverflow.com/questions/28175420/android-compass-accuracy-when-to-calibrate) StackOverflow question and answer gives more options for the value. They come from SensorManager class. Some examplery code of the approach decribed there:
switch(sensor.getType()) {
case Sensor.TYPE_MAGNETIC_FIELD :
switch(accuracy) {
case SensorManager.SENSOR_STATUS_ACCURACY_LOW :
doSomething();
break;
case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM :
doSomethingElse();
break;
case SensorManager.SENSOR_STATUS_ACCURACY_HIGH :
doNothing();
break;
}
break;
default:
break;
}
Those functions should be returning a value between 0 and 1. For Low there would be value 0, for Medium 0.5 and High 1 for example. Would that work?
Dear developer
does this package work with Expo?
i'm getting error: null is not an object(evaluating 'CompassHeading.start')
Regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.