Reputation: 332
I am trying to use:
navigator.geolocation.getCurrentPosition
but when I evaluate navigator.geolocation, I get:
navigator.geolocation is undefined
Upvotes: 0
Views: 1623
Reputation: 5472
In your scenario since React Native version 0.60 the Geolocation module was migrated out of React Native Core. For more information follow docs
Migrating from the core react-native module
OLD :
navigator.geolocation.setRNConfiguration(config);
UPDATED :
import Geolocation from '@react-native-community/geolocation';
Geolocation.setRNConfiguration(config);
For your problem use like this:
import Geolocation from '@react-native-community/geolocation';
Geolocation.getCurrentPosition(info => console.log(info));
Upvotes: 1
Reputation: 332
You have to import Geolocation as a separate module after installing it:
import Geolocation from '@react-native-community/geolocation';
const locationConfig = {skipPermissionRequests:false,authorizationLevel:"whenInUse"}
Geolocation.setRNConfiguration(locationConfig);
Then you call Geolocation.getCurrentPosition
Upvotes: 1