Getting User's Location in iOS

I’m using the code at the end of the “Native Features” section in the Ultimate React Native: Advanced course. But, am getting the following error when trying to get the location of my iOS simulator:
null is not an object (evaluating '_await$Location$getLa.coords')

When I change the hook to use Location.getCurrentPositionAsync() that works.
Any help would be great!

1 Like

I ran into the same thing. In the course video, Mosh recommends using Location.getLastKnownPosition, but that throws the error you noted. Could just be an Xcode Simulator issue – I didn’t try it on actual hardware.

Location.getCurrentPositionAsync seems to work consistently.

Agree with you,
whet I found here :slight_smile: Location - Expo Documentation
Returns a promise resolving to an object of type LocationObject or null if it’s not available or doesn’t match given requirements such as maximum age or required accuracy.

It means we can use getLastKnownPositionAsync if its already known otherwise we use getCurrentPositionAsync as it s more up to date but consume more time getCurrentPositionAsync

Good catch! That explains the behavior.

getCurrentPositionAsync worked best!

Thanks