Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] What's the best way to determine where device is heading to #2159

Open
alifa20 opened this issue Oct 2, 2024 · 1 comment
Open

Comments

@alifa20
Copy link

alifa20 commented Oct 2, 2024

Your Environment

  • Plugin version: ^4.17.1
  • Platform: iOS
  • OS version: 14.6.1 (23G93)
  • Device manufacturer / model:
  • React Native version (react-native -v): 0.74.5
  • Plugin config
  useEffect(() => {
    const onLocation: Subscription = BackgroundGeolocation.onLocation(
      (location) => {
        console.log("[onLocation]", location);
        setLocation(location);
      }
    );

    const onMotionChange: Subscription = BackgroundGeolocation.onMotionChange(
      (event) => {
        console.log("[onMotionChange]", event);
      }
    );

    const onActivityChange: Subscription =
      BackgroundGeolocation.onActivityChange((event) => {
        console.log("[onActivityChange]", event);
      });

    const onProviderChange: Subscription =
      BackgroundGeolocation.onProviderChange((event) => {
        console.log("[onProviderChange]", event);
      });

    BackgroundGeolocation.ready({
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      distanceFilter: 10,
      locationAuthorizationRequest: "WhenInUse",

      stopTimeout: 5,

      debug: false,
      logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
      stopOnTerminate: false,
      startOnBoot: true,
      stopOnStationary: false,
      desiredOdometerAccuracy: 10,
      stationaryRadius: 5,

      batchSync: false,
      autoSync: true,
    }).then((state) => {
      setEnabled(true);
      console.log(
        "- BackgroundGeolocation is configured and ready: ",
        JSON.stringify(state.enabled)
      );
    });

    return () => {
      onLocation.remove();
      onMotionChange.remove();
      onActivityChange.remove();
      onProviderChange.remove();
    };
  }, []);

Expected Behavior

I'm having trouble with location?.coords.heading, which often returns -1, likely because the GPS isn't reliable. The library does a good job tracking speed, but I need a better way to figure out the direction the user is heading so I can show it on the map.

I've looked through the docs but haven't found a good solution. Has anyone else dealt with this or found a better way to estimate the user's direction?

Any help would be great!

@alifa20 alifa20 closed this as completed Oct 2, 2024
@alifa20 alifa20 reopened this Oct 2, 2024
@alifa20 alifa20 changed the title [Question] [Question] What's the best way to determine where device is heading Oct 2, 2024
@alifa20 alifa20 changed the title [Question] What's the best way to determine where device is heading [Question] What's the best way to determine where device is heading to Oct 2, 2024
@christocracy
Copy link
Member

It’s not unusual to see heading: -1.

GPS only works outdoors and heading only comes from GPS.

you are not guaranteed to always receive heading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants