Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

475
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda