react-native-geolocation
react-native-geolocation copied to clipboard
iOS : undefined is not an object (evaluating 'navigator.geolocation.getCurrentPosition')
Ask your Question
I am using RN 0.60, Xcode 10.2. Package.json : "@react-native-community/geolocation": "^1.4.2" Podfile : pod 'react-native-geolocation', path: '../node_modules/@react-native-community/geolocation'
My Android app is running fine, but on Xcode I get error
undefined is not an object (evaluating 'navigator.geolocation.getCurrentPosition')
As it is running fine on android I assume it is IOS installation issue.
Steps I followed
- npm install @react-native-community/geolocation --save
- react-native link @react-native-community/geolocation
- Added to info.plist :
<key>NSLocationWhenInUseUsageDescription</key> <string>Get current location</string>
- Added
pod 'react-native-geolocation', path: '../node_modules/@react-native-community/geolocation'
to pod file - Pod install
No luck, any help ?? can anybody tell me where I am going wrong ?
It is giving error for this function navigator.geolocation.getCurrentPosition
From the readme: https://github.com/react-native-community/react-native-geolocation#migrating-from-the-core-react-native-module:
Change:
navigator.geolocation.setRNConfiguration(config);
to
import Geolocation from '@react-native-community/geolocation';
Geolocation.setRNConfiguration(config);
(in your case obviously replace setRNConfiguration with getCurrentPosition).
@geisterfurz007 Thank you for your reply. Now I am getting error undefined is not a function (near '.._geolocation.default.sgetCurrentPosition..')
. I think it is some installation issue as it is working with android. As the readme suggested it was only for migration use so I did not try it initially.
sgetCurrentPosition
I am pretty sure it's just a typo (little s in the beginning too much).