Location permission
- React Native course
- Intermediate
- Lesson 109/116
- 5 min
Learn to ask for location permission.
Location permission
Location permission is the approval required for the app to receive GPS data. It is requested with Permissions.askAsync(Permissions.LOCATION). If status === 'granted' the location can be fetched; otherwise the map or nearby places feature will not work.
Location permission has two types: foreground (while the app is open) and background (when closed). In Expo Permissions.LOCATION is for foreground; background needs extra setup. Background location is more sensitive; users are more cautious about it. That is why it should be requested only when truly needed. Location is personal data; asking with a good explanation keeps user trust.
Foreground vs background
Foreground location reads GPS data while the app is open on screen. Permissions.LOCATION gives this. It is enough for showing a map, listing nearby places.
Background location reads location even when the app is closed. This is needed for apps that require continuous tracking like navigation or fitness. It is more sensitive; App Store and Play Store review it strictly. Background location requires UIBackgroundModes on iOS and the ACCESS_BACKGROUND_LOCATION permission on Android. Expo configures these in app.json. Asking for background location without need can be intrusive enough to drive users away.
Practice Write requestLocationPermission
Write a requestLocationPermission function. Make it async. Call Permissions.askAsync(Permissions.LOCATION) with await; return status.
Starter code
// Write the requestLocationPermission function
// Ask LOCATION permission with Permissions.askAsync; give back the statusSample solution
async function requestLocationPermission() {
const { status } = await Permissions.askAsync(Permissions.LOCATION);
return status;
}Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Match each type to its role
| Term | Meaning |
|---|---|
Permissions.LOCATION |
Foreground location |
background |
Location while closed |
GPS |
Location source |
'granted' |
Permission given |
2 LOCATION permission
await Permissions.askAsync(Permissions.____);
await Permissions.askAsync(Permissions.LOCATION);
Explanation: Permissions.LOCATION is the location permission.
3 Why is location permission requested?
Permissions.askAsync(Permissions.LOCATION);- To get GPS data Correct answer
- To press a button
- To send notifications
- To store files
Explanation: Location permission is requested to get GPS data.