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

Geolocation.requestAuthorization({ authorizationLevel : "whenInUse" }) #252

Closed raghvendra007 closed 2 years ago

raghvendra007 commented 3 years ago

Geolocation.requestAuthorization({ authorizationLevel : "whenInUse" }).then(res=> console.log("result>>",res) ) response came ,"disabled" but it throw popup and in fraction of seconds pop up disseaper in IOS ,iphonex device

Agontuk commented 3 years ago

Parameter is a string, not an object.

Geolocation.requestAuthorization("whenInUse");
raghvendra007 commented 3 years ago

when result is disabled ,it is showing popup to enable location services and just dissaper, how to hold the pop for for few second or how can i stop popup coming on screen ,location services is off then result is coming disabled in IOS

Agontuk commented 3 years ago

which version are you using ?

udimasaryo commented 3 years ago

Hi, I'm also facing the same issue. Seems the "Turn On Location Service" prompt is a bit unreliable on iOS.

  1. The prompt from getCurrentPosition will only show for a brief moment.
  2. The prompt from watchPosition will show normally.
  3. Sometimes after selecting either "Cancel" or "Settings", the prompt from both API will never show up anymore even after killing the app. Prompt will start to show up again after uninstalling and reinstalling the app.

My current workaround is to check for the disabled value from the requestAuthorization and show my own prompt. (Not written in the sample code)

"react-native": "0.63.4", "react-native-geolocation-service": "^5.3.0-beta.1"

Code to reproduce:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow strict-local
 */

import React from 'react';
import {
  SafeAreaView,
  StyleSheet,
  ScrollView,
  View,
  StatusBar,
  Button,
  PermissionsAndroid,
  Platform,
} from 'react-native';
import Geolocation from 'react-native-geolocation-service';

const getPermission = () => {
  if (Platform.OS === 'android') {
    PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
      {
        title: 'Hello',
        message: 'Please allow location access',
        buttonNeutral: 'Ask Me Later',
        buttonNegative: 'Cancel',
        buttonPositive: 'OK',
      },
    ).then((granted) => console.log(granted));
  } else {
    Geolocation.requestAuthorization('whenInUse')
    .then((granted) => console.log(granted));
  }
};

const getCurrentLocation = () => {
  Geolocation.getCurrentPosition(
    (position) => {
      console.log(position);
    },
    (error) => {
      console.log(error);
    },
    {
      enableHighAccuracy: true,
      timeout: 10000,
      maximumAge: 10000,
      showLocationDialog: false
    }
  );
};

const startWatchPosition = () => {
  Geolocation.watchPosition(
    (position) => {
      console.log(position);
    },
    (error) => {
      console.log(error);
    },
  );
};

const stopObserving = () => {
  Geolocation.stopObserving();
};

const App: () => React$Node = () => {
  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView>
        <ScrollView
          contentInsetAdjustmentBehavior="automatic"
          style={styles.scrollView}>
          <View style={styles.body}>
            <Button title="Get Permission" onPress={() => getPermission()} />
            <Button
              title="Get Current Position"
              onPress={() => getCurrentLocation()}
            />
            <Button
              title="Start Watch Position"
              onPress={() => startWatchPosition()}
            />
            <Button
              title="Stop Watch Position"
              onPress={() => stopObserving()}
            />
          </View>
        </ScrollView>
      </SafeAreaView>
    </>
  );
};

const styles = StyleSheet.create({
  scrollView: {},
  engine: {
    position: 'absolute',
    right: 0,
  },
  body: {
    backgroundColor: 'white',
  },
  sectionContainer: {
    marginTop: 32,
    paddingHorizontal: 24,
  },
  sectionTitle: {
    fontSize: 24,
    fontWeight: '600',
    color: 'black',
  },
  sectionDescription: {
    marginTop: 8,
    fontSize: 18,
    fontWeight: '400',
  },
  highlight: {
    fontWeight: '700',
  },
  footer: {
    fontSize: 12,
    fontWeight: '600',
    padding: 4,
    paddingRight: 12,
    textAlign: 'right',
  },
});

export default App;
Agontuk commented 2 years ago

Please try the latest version. Closing this for now as I've failed to reproduce it.

rajanbalana commented 2 years ago

I'm also witnessing the same issue with the latest version of the library.

nachoSource commented 8 months ago

I'm still struggling with this using version 5.3.1 😢