Location.watchPositionAsync + getCurrentPosition explodes

#1

I need to monitor a user’s location and then create a record when he’s in a certain region. To balance battery life and accuracy, I’m using Location.watchPositionAsync({ enableHighAccuracy: false }) but double checking the location data with a Location.getCurrentPosition({ enableHighAccuracy: true }) before actually creating the record.

watchPositionAsync is working alright, but explodes (a callback counter goes to the hundreds in a few seconds) if getCurrentPosition is also called elsewhere in the component.

I’ve also tried using Expo.Location.watchPositionAsync and React Native navigator.geolocation.getCurrentPosition to see if that has any effect.

Is this a glitch, or are these functions incompatible?

0 Likes

#2

Hi-

Can you paste your actual code here with a little bit of context? I’m not totally sure if they are incompatible or not but sometimes things blow up in RN bc of a mistake in the way they are called (type errors, etc.)

0 Likes

#3

Sure, here’s a condensed version:

Everything works okay, and the watchPositionAsync counter shows that the callback is firing BOTH when the watchPositionAsync and getCurrentLocation events happen, followed by exponential growth. Doesn’t seem to matter if it’s an Expo or React Native location tool?

Could very well be my mistake. :confused:

0 Likes

#4

Hmm… interesting. Are you saying that you’ve tried this outside of Expo, in a vanilla RN app, and you’re seeing the same stuff?

0 Likes

#5

I’ve tried both vanilla and Expo geolocation tools, in different combinations. All seem to have this issue, which points to my code being the real problem but I don’t see what I’m doing differently than the docs? It only happens when I try to “watch” and get an extra current position at the same time.

Update: Just for kicks, since Location was mentioned in the v16 release notes, I created a new Expo v16 app with nothing but a bare-bones Location watch every 1200 meters and every 2 pings a getCurrentPosition implemented (Xcode freeway simulation). No change, still explodes.

0 Likes

#6

I"m seeing something similar and am also using watchPositionAsync and getCurrentPosition elsewhere.

I was hoping to just watch the location in general, and use getCurrentPosition when submitting a form where I want to be doubly sure I have he latest location.

0 Likes

#7

can you post your code?
sometimes i’ve seen this happen when people don’t pass anything for the options to one of these functions. i think you have to pass {}. We’ll probably change that so it accepts either.

0 Likes

#8

I’ve tried with different combinations of options, but never zero options?

0 Likes