Search code examples
react-nativegeolocation

cannot read property 'getCurrentPosition' into react native project


Context :

  • Project : React-native
  • Init : expo init project
  • test env : Android device + web browser
  • React native version : 0.71.8
  • React version : 18.2.0

I want to try to work with Geolocation into device for react-native project

Issue :

cannot read property 'getCurrentPosition' with 2 differents react-native library

with :

import Geolocation from 'react-native-geolocation-service'
Geolocation.getCurrentPosition()

or with :

import Geolocation from '@react-native-community/geolocation'
Geolocation.getCurrentPosition(info => console.log(info))

Impossible to get Position into Android device (but ok into browser web)

What is the best official library for working with geolocation into react native ?

Needs 2 base code ? One for iOS other for Android ?

Just 1 library can work into iOS and Android ?

Why I can't 'getCurrentPosition' ?


Solution

  • As you are using Expo, use the Geolocation package optimized for Expo ecosystem - https://docs.expo.dev/versions/latest/sdk/location/