File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " react-native-get-location" ,
33 "displayName" : " React-Native Get Location" ,
4- "version" : " 4.0.0 " ,
4+ "version" : " 4.0.1 " ,
55 "description" : " ⚛ Simple to use React Native library to get device location for Android and iOS." ,
66 "main" : " src" ,
77 "license" : " MIT" ,
Original file line number Diff line number Diff line change 2222 * SOFTWARE.
2323 */
2424
25- import { PermissionsAndroid , Rationale } from 'react-native' ;
25+ import { PermissionsAndroid , Rationale } from 'react-native' ;
2626
2727import LocationError from './LocationError' ;
2828
29+ const { PERMISSIONS , RESULTS } = PermissionsAndroid ;
30+
2931export type Location = {
3032 /**
3133 * The latitude, in degrees
@@ -93,14 +95,15 @@ export async function requestAndroidPermission(
9395 enableHighAccuracy : boolean = false ,
9496 rationale ?: Rationale ,
9597) {
96- const { PERMISSIONS , RESULTS } = PermissionsAndroid ;
98+ const permission = enableHighAccuracy
99+ ? PERMISSIONS . ACCESS_FINE_LOCATION
100+ : PERMISSIONS . ACCESS_COARSE_LOCATION
101+
102+ const alreadyGranted = await PermissionsAndroid . check ( permission ) ;
103+
104+ if ( alreadyGranted ) return true ;
97105
98- const granted = await PermissionsAndroid . request (
99- enableHighAccuracy
100- ? PERMISSIONS . ACCESS_FINE_LOCATION
101- : PERMISSIONS . ACCESS_COARSE_LOCATION ,
102- rationale ,
103- ) ;
106+ const granted = await PermissionsAndroid . request ( permission , rationale ) ;
104107
105108 if ( granted !== RESULTS . GRANTED ) {
106109 throw new LocationError ( 'UNAUTHORIZED' , 'Authorization denied' ) ;
You can’t perform that action at this time.
0 commit comments