Skip to content
Advertisement

Getting location from another file using Promise in react native with react-native-geolocation-service

I’m trying to make a helper function to get the current location of the user, but the result of my promise is undefined.

This function is working and I can retrieve my coordinates :

JavaScript

But when I call my function here, I get undefined :

JavaScript

What am I doing wrong?

Advertisement

Answer

As written, getUserLocation() does not return its request(…).then() promise. Change await to return.

Also, you should really change console.log('Location is not enabled') to throw new Error('Location is not enabled'), thus allowing getUserLocation’s caller to see the error (should it arise).

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement