getCurrentPositionAsync() is taking too much time to fetch location in iOS devices

I am using getCurrentPositionAsync() from expo-location to fetch user’s location and this is how I am using this

import * as Location from "expo-location";

Location.getCurrentPositionAsync({
        accuracy: 6
}).then(currentPosition => {
	console.log('user location', currentPosition);
});

In all Android devices it’s taking hardly 2 seconds to capture location. But in all iOS devices it takes more than 8 seconds(I am confirming this by testing in multiple iOS devices) even though mobile network is so good.

Do I have to do anything else especially for the sake of iOS devices?

If nothing is required especially for iOS devices, May I know why is it taking too much time in iOS devices only?

I have found lots of reports of this issue but nowhere a good answer.

In Balanced accuracy we get very bad coordinates and up to 8 seconds to get them

Is there any solution to this for ios ?

1 Like

Hey @ivonig, if you can share a minimal reproducible example so that I can clone and test it on my end?

Hello @amanhimself

I’m using the code sample from the documentation in my project:

import React, { useState, useEffect } from 'react';
import { Platform, Text, View, StyleSheet } from 'react-native';
import * as Location from 'expo-location';

export default function App() {
  const [location, setLocation] = useState(null);
  const [errorMsg, setErrorMsg] = useState(null);

  useEffect(() => {
    (async () => {
      let { status } = await Location.requestForegroundPermissionsAsync();
      if (status !== 'granted') {
        setErrorMsg('Permission to access location was denied');
        return;
      }

      let location = await Location.getCurrentPositionAsync({});
      setLocation(location);
    })();
  }, []);

  let text = 'Waiting..';
  if (errorMsg) {
    text = errorMsg;
  } else if (location) {
    text = JSON.stringify(location);
  }

  return (
    <View style={styles.container}>
      <Text style={styles.paragraph}>{text}</Text>
    </View>
  );
}

The problem is NOT reproductible on Android or ios Emulator but is when in testflight for example from all the iphones tried.

For information I have seens multiple mention of this problem on discord, also it is in this github thread Location.getCurrentPositionAsync() Takes 10+ seconds after upgrading to SDK39 on iOS · Issue #10756 · expo/expo · GitHub or also this forum thread Location.getCurrentPositionAsync() takes 10+ seconds - #3 by herbertlim . Some alternative have been mentionned but nowhere have I found a reason/solution.

For me, lowering the accuracy did not make it faster but did indeed lost in precision.

I have an older version of the app on SDK 42 and expo-location 10 and it works perfectly (fast and precise) on the exact same iphones where now it takes 10sec +.

IMPORTANT EDIT: An important info I just tested, using Location.watchPositionAsync(options, callback) instead of Location.getCurrentPositionAsync with the same implementation works fast on the exact same Iphones (we get precision and fast coordinates) which confirms that there is most probably a bug in the Location.getCurrentPositionAsync method.

Can I ask you to open a GitHub issue or at least add your findings to this GitHub issue which is open: https://github.com/expo/expo/issues/10756#issuecomment-728382658? Maybe as workaround, it will help others who are also coming across this.

I’ll try to reproduce it on my end, thanks!

1 Like

Actually I got the workaround from there. It was mentionned Location.getCurrentPositionAsync() Takes 10+ seconds after upgrading to SDK39 on iOS · Issue #10756 · expo/expo · GitHub I’ll confirm it’s indeed a working workaround

1 Like

Thank you!