Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

472
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!