import { PermissionsAndroid , Platform } from "react-native" ; import Geolocation , { GeolocationStatic } from "@react-native-community/geolocation" ; returns { Promise . < boolean > } export async function RequestLocationPermission ( ) { if ( navigator && navigator . product === "ReactNative" ) { if ( ! navigator . geolocation ) { ( navigator . geolocation as GeolocationStatic ) = Geolocation ; } if ( Platform . OS === "android" ) { const locationPermission = PermissionsAndroid . PERMISSIONS . ACCESS_FINE_LOCATION ; return PermissionsAndroid . check ( locationPermission ) . then ( hasPermission => hasPermission ? true : PermissionsAndroid . request ( locationPermission ) . then ( status => status === PermissionsAndroid . RESULTS . GRANTED ) ) ; } else if ( navigator . geolocation && ( navigator . geolocation as GeolocationStatic ) . requestAuthorization ) { try { ( navigator . geolocation as GeolocationStatic ) . requestAuthorization ( ) ; return Promise . resolve ( true ) ; } catch ( error ) { return Promise . reject ( error ) ; } } } return Promise . reject ( new Error ( "No permission request for location is required for web/hybrid platform" ) ) ; }