webyonet / react-native-android-location-services-dialog-box

React Native Android Location Services Dialog Box
MIT License
182 stars 50 forks source link

Location is already enabled but location service dialog box is showing #37

Closed Sathiyamm closed 6 years ago

Sathiyamm commented 6 years ago

I use this code

import { BackHandler } from 'react-native';
import LocationServicesDialogBox from "react-native-android-location-services-dialog-box";
export function requestLocationPermission() {
    try {
LocationServicesDialogBox.checkLocationServicesIsEnabled({
    message: "<h2>Use Location ?</h2>This app wants to change your device settings:<br/><br/>Use GPS, Wi-Fi, and cell network for location<br/><br/><a href='#'>Learn more</a>",
    ok: "YES",
    cancel: "NO",
    enableHighAccuracy: true, // true => GPS AND NETWORK PROVIDER, false => ONLY GPS PROVIDER
    showDialog: true, // false => Opens the Location access page directly
    openLocationServices: true, // false => Directly catch method is called if location services are turned off
    preventOutSideTouch: false, //true => To prevent the location services window from closing when it is clicked outside
    preventBackClick: false //true => To prevent the location services popup from closing when it is clicked back button
}).then(function(success) {
    console.log(success); // success => {alreadyEnabled: false, enabled: true, status: "enabled"}
}).catch((error) => {
    console.log(error.message); // error.message => "disabled"
});

BackHandler.addEventListener('hardwareBackPress', () => { //(optional) you can use it if you need it
   LocationServicesDialogBox.forceCloseDialog();
});
} catch (err) {
        console.warn(err)
    }
}
Sathiyamm commented 6 years ago

enableHighAccuracy: true, // true => GPS AND NETWORK PROVIDER, false => ONLY GPS PROVIDER

I change enableHighAccuracy: false, it's working correctly.