React-native-google-places-autocomplete: navigator.geolocation.getCurrentLocation is undefined

Created on 6 Aug 2019  路  6Comments  路  Source: FaridSafi/react-native-google-places-autocomplete

I have fixed this issue by the following steps,

In GooglePlacesAutocomplete.js file,

importing Geolocation from '@react-native-community/geolocation' at the top,
and
replacing navigator.geolocation.getCurrentPosition to Geolocation.getCurrentPosition

bug

Most helpful comment

I fixed it without edit files in node_modules folder.

Refer to @react-native-community/geolocation

If you need to have geolocation API aligned with the browser (cross-platform apps), or want to support backward compatibility, please consider adding following lines at the root level, for example at the top of your App.js file (only for react native):

navigator.geolocation = require('@react-native-community/geolocation');

All 6 comments

i'm using RN0.60 https://facebook.github.io/react-native/docs/geolocation and please post where i should make this changes since RN0.60 auto loads navigator.geolocation i Couldn't find the path for this change

@joeljerushan Inside node_modules

node_modules/react-native-google-places-autocomplete/GooglePlacesAutocomplete.js

And please make sure to,

npm install or yarn add @react-native-community/geolocation

Since the one you have linked is deprecated.

I fixed it without edit files in node_modules folder.

Refer to @react-native-community/geolocation

If you need to have geolocation API aligned with the browser (cross-platform apps), or want to support backward compatibility, please consider adding following lines at the root level, for example at the top of your App.js file (only for react native):

navigator.geolocation = require('@react-native-community/geolocation');

@Alishgiri following your instructions I got, NativeModule.RNCGeolocation is null. To fix this issue try these steps: Run 'react-native-link' etc do you know how can I fix this?

@Alishgiri following your instructions I got, NativeModule.RNCGeolocation is null. To fix this issue try these steps: Run 'react-native-link' etc do you know how can I fix this?

I will assume that you have installed geolocation package,

npm install or yarn add @react-native-community/geolocation

if that issue you are facing is on Android (for RN <= 60.4),
and if you are using React native navigation, add the following to MainApplication.java

import com.reactnativecommunity.geolocation.GeolocationPackage;
protected List<ReactPackage> getPackages() { ... new GeolocationPackage(), ... }

or if the issue is on iOS (react-native link @react-native-community/geolocation should work for RN < 59.x). for RN > 60.x add podspec to podfile:
pod 'react-native-geolocation', path: '../node_modules/@react-native-community/geolocation'

don't forget to run pod install on the ios folder.

@carmelocatalfamo a quick question. Where am I supposed to edit this? Change this navigator config?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

frankfaustino picture frankfaustino  路  4Comments

quandevelopment picture quandevelopment  路  4Comments

nikohosn picture nikohosn  路  3Comments

mbelgrader picture mbelgrader  路  4Comments

DennisMuchiri picture DennisMuchiri  路  4Comments