lzx1996
1
Please provide the following:
- SDK Version: 48.0.16
- Platforms(Android/iOS/web/all): Android
- Add the appropriate “Tag” based on what Expo library you have a question on.
expo-location: 15.1.1
On android, expo-location CurrentPositionAsync() take super long time to resolve!
Methods I have tried,
- Location.getCurrentPositionAsync() sometimes never responds or takes a very long time to respond · Issue #10756 · expo/expo · GitHub
- setting accuracy to balanced.
However, it still take very long time to resolve.
Anyone facing the same problem?
lzx1996
2
This is my Code
export const fetchGPSLocation = (current_location = false) => {
return new Promise(async (resolve, reject) => {
let location = null;
let tries = 1;
do {
try {
if (current_location || tries >= 2) {
location = await Promise.race([
sleeping(5000),
getCurrentPositionAsync({
accuracy: LocationAccuracy.Balanced,
}),
])
} else {
location = await Promise.race([
sleeping(2500),
getLastKnownPositionAsync({
maxAge: 60 * 1000,
requiredAccuracy: LocationAccuracy.Balanced,
})
])
}
if (location) {
return resolve(location)
}
tries++;
} catch {
tries++;
// console.log('error tries = ' + tries.toString(), new Date().toLocaleString())
}
} while (location == null && tries < 3)
return reject(t('errors.gps-error', {tries}));
})
}