Env setup:
Expo CLI 3.4.1 environment info:
System:
OS: macOS 10.15.4
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.12.0 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.11.3 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5900203
Xcode: 11.1/11A1027 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.2 => 0.61.2
react-navigation: ^4.0.10 => 4.0.10
npmGlobalPackages:
expo-cli: 3.4.1
In some Android throws the error when call getCurrentPositionAsync({ })
Location provider is unavailable. Make sure that location services are enabled.
The service is enable. Everything is configured properly. On iOS works fine. In some Android works and others don’t. I’m not gonna use react-native-geolocation-service due this is basic use of the lib on Android and iOS. Also I have tried a variety of options params.
Code snippet:
import { Platform } from 'react-native'
import { Constants, Permissions } from 'react-native-unimodules'
import * as L from 'expo-location'
class Location {
static getAsync = async () => {
if (Platform.OS === 'android' && !Constants.isDevice) {
throw new Exception('Geolocation only in devices not emulators.')
}
try{
let location = null
const {status: granted} = await Permissions.getAsync(Permissions.LOCATION);
if(granted === 'granted'){
location = await L.getCurrentPositionAsync({ accuracy: L.Accuracy.Balanced })
return {status: granted, location: location, granted: (granted === 'granted')}
}
const {status} = await Permissions.askAsync(Permissions.LOCATION)
if(status === 'granted'){
location = await L.getCurrentPositionAsync({ accuracy: L.Accuracy.Balanced })
return {status: status, location: location, granted: (status === 'granted')}
}
return {status: status, location: location, granted: (status === 'granted')}
}catch(e){
alert(e)
}
return null
}
}
None these methods work:
getLastKnownPositionAsync
watchPositionAsync
getCurrentPositionAsync