Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.61k stars 292 forks source link

Fetch location problem while app goes in background (ios) #392

Open kikanikishan opened 1 year ago

kikanikishan commented 1 year ago

Environment

System: OS: macOS 12.6.1 CPU: (4) x64 Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz Memory: 24.20 MB / 8.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 14.18.0 - ~/.nvm/versions/node/v14.18.0/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.1.1 - ~/.nvm/versions/node/v14.18.0/bin/npm Watchman: 2022.11.14.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: Not Found Xcode: 14.1/14B47b - /usr/bin/xcodebuild Languages: Java: 11.0.15 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.68.2 => 0.68.2 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Platforms

It's issue with ios platform.

Versions

Description

I am implemented getCurrentlocation API in specific interval and i want to get location data on every 20 seconds so that I store this location in our server. I follow setup file for background fetch. docs/setup.md Here, below I provide a code snippet

  const location interval = async () => {
    locationTimeinterval = setInterval(async () => {
      //for geolocation
      Geolocation.getCurrentPosition(
        async position => {
          console.log('locationcurrentsuccess: ', position);
        },
        error => {
          console.log({error});
        },
        {
          enableHighAccuracy: true,
          timeout: 15000,
          maximumAge: 10000,
        },
      );
    }, 20000);
  };

As per the code, I added getCurrentPosition API in the interval and fetch location data. => This code is working fine in the foreground. => When I move the app to the background, I am not able to get the location.

So, my request is that please suggest any solution for this issue.

Thanks in advance.

Sondouni commented 1 year ago

did you solve this?

kikanikishan commented 1 year ago

No, I tried all possibilities but it's not working at all.

wmonecke commented 1 year ago

Hey, we are also facing this issue. We did have this working at some point but it seemingly stopped working out of the blue. Any ideas? We are thinking of migrating to another lib.

kikanikishan commented 10 months ago

anyone find any solution ?

Ppang0405 commented 9 months ago

did you guys try expo-location https://docs.expo.dev/versions/latest/sdk/location/#locationstartlocationupdatesasynctaskname-options

I see it supports both foreground and background execution mode for location updates.