react-native-geolocation icon indicating copy to clipboard operation
react-native-geolocation copied to clipboard

iOS : undefined is not an object (evaluating 'navigator.geolocation.getCurrentPosition')

Open blueneel05 opened this issue 5 years ago • 3 comments

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

  1. npm install @react-native-community/geolocation --save
  2. react-native link @react-native-community/geolocation
  3. Added to info.plist : <key>NSLocationWhenInUseUsageDescription</key> <string>Get current location</string>
  4. Added pod 'react-native-geolocation', path: '../node_modules/@react-native-community/geolocation' to pod file
  5. 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

blueneel05 avatar Aug 15 '19 08:08 blueneel05

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).

mvarendorff avatar Aug 15 '19 09:08 mvarendorff

@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.

blueneel05 avatar Aug 15 '19 12:08 blueneel05

sgetCurrentPosition I am pretty sure it's just a typo (little s in the beginning too much).

mvarendorff avatar Aug 15 '19 16:08 mvarendorff