Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

471
Vistas
React Native - expo getCurrentPositionAsync not working

So I'm trying to get the users current co-oridnates from expo-location and testing it using the expo client on my android phone. The code below logs status as approved but latitude and longitude don't get updated and on iphone I get the following error:

[Unhandled promise rejection: Error: Request failed with status code 400] at node_modules/axios/lib/core/createError.js:15:17 in createError at node_modules/axios/lib/core/settle.js:16:9 in settle at node_modules/axios/lib/adapters/xhr.js:52:6 in handleLoad at node_modules/react-native/Libraries/Network/XMLHttpRequest.js:601:4 in setReadyState at node_modules/react-native/Libraries/Network/XMLHttpRequest.js:396:6 in __didCompleteResponse at node_modules/react-native/Libraries/vendor/emitter/_EventEmitter.js:135:10 in EventEmitter#emit

Code:

    const [latitude, setLatitude] = useState();
    const [longitude, setLongitude] = useState();
    const getLocationAsync = async () => {
        let { status } = await Location.requestForegroundPermissionsAsync();
    
        if (status === 'granted') {
            console.log('Approved!');
            return Location.getCurrentPositionAsync({ enableHighAccuracy: true });
        } else {
           console.log('Rejected!');
           throw new Error('Location permission not granted');
        }
    }
    useEffect(() => {
        const location = getLocationAsync();
        setLatitude(location.latitude);
        setLongitude(location.longitude);
    }, []);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

getLocationAsync is promise function.

you can change this code

 useEffect(() => {
    (async () => {
      const { status } = await Location.requestForegroundPermissionsAsync();
    
        if (status === 'granted') {
           console.log('Approved!');
           const location = await Location.getCurrentPositionAsync({ enableHighAccuracy: true });
           setLatitude(location.latitude);
           setLongitude(location.longitude);
        } else {
           console.log('Rejected!');
           throw new Error('Location permission not granted');
        }
    })();
  }, []);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda