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 291 forks source link

How to get rid of blue bar in background #298

Closed junaidrazaq closed 2 years ago

junaidrazaq commented 3 years ago

I'm using the watchPosition function and the location is being tracked successfully, but for some reason, the location is being tracked in the background also. I don't mind this but the blue bar is showing on the top when the app is in the background. How could i go about removing this? Thanks

` handlePermission = async unmount => { let isGranted;

if (Platform.OS === 'android') {
  isGranted = await request(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION);
} else {
  isGranted = await request(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE);
}
if (isGranted === RESULTS.GRANTED) {
  const _watchId = Geolocation.watchPosition(
    position => {
      const {latitude, longitude} = position.coords;
      setCurrentLocation({lat: latitude, lng: longitude});
    },
    error => {
      console.log(error);
    },
    {
      enableHighAccuracy: true,
      timeout: 1000,
      distanceFilter: 100,
      interval: 5000,
      fastestInterval: 2000,
    },
  );
  if (unmount === 'unsubscribe') {
    console.log('removing listeners');
    Geolocation.clearWatch(_watchId);
  }
}
}

useEffect(() => {
  handlePermission();

  return () => {
    handlePermission('unsubscribe');
  };
}, []);`
Agontuk commented 3 years ago

showsBackgroundLocationIndicator: false should solve this issue.

junaidrazaq commented 3 years ago

Doesn't work. I have version 5.0.0, maybe that's why? I will try to upgrade and let you know if that works, Thanks

junaidrazaq commented 3 years ago

Nope, same issue on version 5.2.2. IOS btw

ivangonzalezg commented 2 years ago

You have to enable location updates capability for your app in Xcode.

Open Xcode

  1. Click on your app name
  2. Open Signing & Capabilities
  3. Add Background mode to capabilities (if not added)
  4. Check Location updates

image

Now you can use the watchPosition function and then when your app go to background the blue bar appears (THE AUTHORIZATION LEVEL MUST BE "always")

image

image

marquina-abreu commented 2 years ago

I think that to collect the coordinates in background mode, it only works for iOS... for android it doesn't... I think that for that case you have to resort to another library that is paid

Agontuk commented 2 years ago

Setting showsBackgroundLocationIndicator: false will only work if you're using always authorization. If you're using whenInUse authorization, it'll always show the blue bar. I hope it clears the confusion.

https://developer.apple.com/documentation/corelocation/cllocationmanager/2923541-showsbackgroundlocationindicator