dmn
dmn

Reputation: 21

navigator.geolocation.getCurrentPosition is not working in React Native Version(0.60) and above, How to fetch location?

Trying to fetch current Location using geoLocation, it is not working in React Native version(0.60) and above, But it is working in below versions

I realised, GeoLocation folder is not there in nodeModules/React-Native/Libraries, did they remove it from ReactNative(0.60)?

        navigator.geolocation.getCurrentPosition((position) => {
        console.log(position)
    },
    (error) => alert(JSON.stringify(error)),)

Getting this error:

Type Error: Undefined is not an object(evaluating 'navigator.geolocation.getCurrentPosition

Upvotes: 1

Views: 3081

Answers (2)

Manuel Carmona
Manuel Carmona

Reputation: 367

npm install @react-native-community/geolocation --save

react-native link @react-native-community/geolocation

then:

import Geolocation form '@react-native-community/geolocation';
Geolocation.etCurrentPosition((position) => {
    console.log(position)
},
(error) => alert(JSON.stringify(error))

Upvotes: 0

Jessica Rodriguez
Jessica Rodriguez

Reputation: 2974

It seems geolocation has been removed from react native .60 version.

Try this:

npm install @react-native-community/geolocation --save

react-native link @react-native-community/geolocation

You can check this related SO post for more details.

Upvotes: 2

Related Questions