- Qt 6.9
- Qt Core
- C++ Classes
- QLocationPermission
- Qt 6.9.3 Reference Documentation

# QLocationPermission Class

Access the user's location. More...

Header: | `#include <QPermissions>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::Core)`
qmake: | `QT += core`
Since: | Qt 6.5

- List of all members, including inherited members

## Public Types

enum | Accuracy { Approximate, Precise }
enum | Availability { WhenInUse, Always }

## Public Functions

QLocationPermission::Accuracy | accuracy() const
QLocationPermission::Availability | availability() const
void | setAccuracy(QLocationPermission::Accuracy accuracy)
void | setAvailability(QLocationPermission::Availability availability)

## Detailed Description

By default the request is for approximate accuracy, and only while the application is in use. Use setAccuracy() and/or setAvailability() to override the default.

### Requirements

To request this permission at runtime, the following platform specific usage declarations have to be made at build time:

Platform | Type |
--- | --- | ---
macOS | Usage description | `NSLocationUsageDescription`
iOS | Usage description | `NSLocationWhenInUseUsageDescription`, and `NSLocationAlwaysAndWhenInUseUsageDescription` if requesting QLocationPermission::Always

Android

`uses-permission`

- `android.permission.ACCESS_FINE_LOCATION` for QLocationPermission::Precise
- `android.permission.ACCESS_COARSE_LOCATION` for QLocationPermission::Approximate
- `android.permission.ACCESS_BACKGROUND_LOCATION` for QLocationPermission::Always

Note: QLocationPermission::Always `uses-permission` string has to be combined with one or both of QLocationPermission::Precise and QLocationPermission::Approximate strings.

Please see the individual usage declaration types for how to add them to your project.

See also QPermission, QCoreApplication::requestPermission(), QCoreApplication::checkPermission(), and Application Permissions.

## Member Type Documentation

### enum QLocationPermission::Accuracy

This enum is used to control the accuracy of the location data.

Constant | Value | Description
--- | --- | ---
`QLocationPermission::Approximate` | `0` | An approximate location is requested.
`QLocationPermission::Precise` | `1` | A precise location is requested.

### enum QLocationPermission::Availability

This enum is used to control the availability of the location data.

Constant | Value | Description
--- | --- | ---
`QLocationPermission::WhenInUse` | `0` | The location is only available only when the application is in use.
`QLocationPermission::Always` | `1` | The location is available at all times, including when the application is in the background.

## Member Function Documentation

### QLocationPermission::Accuracy QLocationPermission::accuracy() const

Returns the accuracy of the request.

See also setAccuracy().

### QLocationPermission::Availability QLocationPermission::availability() const

Returns the availability of the request.

See also setAvailability().

### void QLocationPermission::setAccuracy(QLocationPermission::Accuracy accuracy)

Sets the desired accuracy of the request.

See also accuracy().

### void QLocationPermission::setAvailability(QLocationPermission::Availability availability)

Sets the desired availability of the request.

See also availability().