Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React Native Get Current Location

$
0
0

I am trying to get the user's current location when the checkbox "current location" is selected. I have a form with user inputs and when the form is submitted and current location is selected, the app should get the users current location. My issue is that it doesn't ask the user for permission to access their location, the app ignores this request and returns the location coordinates as 0.

I am using multiple Console Log to see where my issue lies and i am using expo location.

Code:

const getLocation = () => {console.log("Testing getLocation");(async () => {  console.log("Ask Location Permission");  let { status } = await Location.requestForegroundPermissionsAsync();  console.log("Permission Asked");  if (status !== "granted") {    setErrorMsg("Location access denied!");    console.log(errorMsg);    return;  }  let currentLocation = await Location.getCurrentPositionAsync({});  setLatitude(currentLocation.coords.latitude);  setLongitude(currentLocation.coords.longitude);  console.log("Start of Print Coords");  console.log(currentLatitude);  console.log(currentLongitude);  console.log("End of Print Coords");})();};const onSubmit = (data: { distance: number; coordinates: string }) => {if (checkbox) {  console.log("Checkbox Selected");  getLocation();  console.log("getLocation Tested");  coords.push(currentLatitude);  coords.push(currentLongitude);  console.log(coords);}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>