I have been following a information to construct a location tracker, however I continually get the error
“Error: One of many NSLocation*UsageDescription
keys have to be current in Data.plist to have the ability to use geolocation.”
And
“Error: Background Location has not been configured. To allow it, add location
to UIBackgroundModes
in Data.plist file.”
Which does not make a lot sense since I already put each of the required stuff within the app.json
import React, { Part, useEffect, useState } from "react";
import { StyleSheet, Textual content, View } from "react-native";
import MapView from "react-native-maps";
import * as Location from "expo-location";
import * as TaskManager from "expo-task-manager";
const LOCATION_TASK_NAME = "background-location-task";
export default perform Display() {
const [region, setRegion] = useState< null;
>({
latitude: 0,
longitude: 0,
latitudeDelta: 0.045,
longitudeDelta: 0.045,
heading: null,
});
const getLocationAsync = async () => {
Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
accuracy: Location.Accuracy.BestForNavigation,
distanceInterval: 1,
timeInterval: 500,
});
const newLocation = await Location.watchPositionAsync(
{
accuracy: Location.Accuracy.BestForNavigation,
distanceInterval: 1,
timeInterval: 10000,
},
({ coords }) => {
setRegion((prev) => ({
...prev,
latitude: coords.latitude,
longitude: coords.longitude,
heading: coords.heading,
}));
}
);
return newLocation;
};
const permissionHandler = async () => {
const { standing } = await Location.requestForegroundPermissionsAsync();
if (standing === "granted") {
// const { standing: backgroundStatus } =
// await Location.requestBackgroundPermissionsAsync();
// if (backgroundStatus === "granted") {
getLocationAsync();
// }
}
};
useEffect(() => {
permissionHandler();
}, []);
return <Textual content>Check</Textual content>;
}
TaskManager.defineTask(LOCATION_TASK_NAME, async ({ information, error }: any) => {
if (error) {
console.log(error);
return;
}
if (information) {
const { areas } = information;
let lat = areas[0].coords.latitude;
let lengthy = areas[0].coords.longitude;
console.log(lat, lengthy);
}
});
App.json
{expo:{
...
"permissions": [
"location",
"fetch"
],
"ios": {
"supportsTablet": true,
"infoPlist": {
"UIBackgroundModes": [
"location",
"fetch",
"remote-notification"
],
"NSLocationWhenInUseUsageDescription": "Your app wants entry to location when in use for...",
"NSLocationAlwaysUsageDescription": "Your app wants entry to location even when the app is within the background for...",
"NSLocationAlwaysAndWhenInUseUsageDescription": "Your app wants entry to location even when the app is within the background for..."
}
},
"plugins": [
[
"expo-location",
{
"locationAlwaysAndWhenInUsePermission": "Allow $(PRODUCT_NAME) to use your location.",
"locationAlwaysPermission": "Allow $(PRODUCT_NAME) to use your location."
}
]
]
}}
I attempted clearing the cache, did not work, resetting the app, additionally did not work....