React-native-geolocation-service: TypeError: Cannot read property 'getCurrentPosition' of undefined

Created on 28 Jan 2019  路  16Comments  路  Source: Agontuk/react-native-geolocation-service

After all setup I have this issue::

> TypeError: Cannot read property 'getCurrentPosition' of undefined
>     at Object.getCurrentPosition$ (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:162211:33)
>     at tryCatch (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21370:19)
>     at Generator.invoke [as _invoke] (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21543:24)
>     at Generator.prototype.(anonymous function) [as next] (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21413:23)
>     at tryCatch (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21370:19)
>     at invoke (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21446:22)
>     at blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21474:13
>     at tryCallTwo (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:20708:7)
>     at doResolve (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:20872:15)
>     at new Promise (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:20731:5)

Steps I have followed::

After these I have installed "react-native-geolocation-service" package
Link this package
I have followed all the Android settings.
Import in file like this:: import Geolocation from "react-native-geolocation-service";
Function where I used it::

getLocation() {
        Geolocation.getCurrentPosition(response => {
            console.log("geo response = ", response);
            if (response && response.coords) {
                console.log("geo res true");
                this.saveLocationLogs(response.coords);
            }
        },
            (error) => {
                console.log("Error geolocation");
                this.onGeolocationErrorOccurCallback(error);
            },
            GeolocationOptions
        ).catch((error) => {
            console.log(error);
        });
    }

There is a TypeError: cannot read property getCurrentPosition of undefined.
still I am not able to get my current location?? Why this is happening? Please suggest me a solution.

Most helpful comment

fuck u github..u dont have solutions for our questions

All 16 comments

I am facing the same problem. Did you find out some solution?

I have created a new sample, follow all the instructions and make some extra changes as mentioned below, it works for me. But I am not able to detect the issue occurring in previous sample.
Typerror::Cannot read property 'getCurrentPosition' of undefined, this occurs if it's not linked properly.
I have linked again .
After this I set googlePlayServicesVersion = "11.0.0" to "16.0.1" , and it's works for me.

I'm having the same problem but changing googlePlayServicesVersion didn't work.

Add this inside build.gradle(Module: app)
implementation "com.google.android.gms:play-services-location:16.0.0"

And Please try to link this manually. It might resolve your issue.

Google play service version may change depending on which android version you're targeting. So try out different versions and see if it works.

Getting the same error, even after making the above mentioned changes.

fuck u github..u dont have solutions for our questions

This can only happen if your setup process was wrong. Make sure the setup is ok and that you added new RNFusedLocationPackage() in MainApplication.java

Check These lines added in your MainApplication.java

import com.agontuk.RNFusedLocation.RNFusedLocationPackage;

new RNFusedLocationPackage() in protected List getPackages() method

It fixes my issue

Closing this, as it's most likely setup issue. Please follow the instructions properly.

Indeed follow the steps for 0.59 and lower if this error occurs. 'No additional setup is required for 0.60 or above' sounds tempting.

@klaasel i was about to say that. I think this should be mentioned in the README so it can help other people in the future as well.

@klaasel i was about to say that. I think this should be mentioned in the README so it can help other people in the future as well.

Pull requests are welcome.

So, you need to follow the steps for 0.59 or lower in order to setup 0.60+ projects ? That shouldn't be needed as far as I know.

I had a similar issue when trying to get user's location. Depending on which version of android you now need to ask for the user to grant location, not only by adding the permission line to the AndroidManifest but also by using AndroidPermissions on the react native code

https://facebook.github.io/react-native/docs/permissionsandroid

Still, make sure you have react native geolocation services installed: https://github.com/Agontuk/react-native-geolocation-service

react-native: 0.61.4
react-native-geolocation-service: 3.1.0

react-native link @react-native-community/react-native-geolocation-service resolved this issue for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chungweileong94 picture chungweileong94  路  5Comments

matthieupinte picture matthieupinte  路  6Comments

ravirajn22 picture ravirajn22  路  4Comments

lyseiha picture lyseiha  路  6Comments

lingxiao-Zhu picture lingxiao-Zhu  路  3Comments