requestLocationPermission
Supported Version
Started support in
zpa
(Zalopay App) 9.18.0 for Android, version 9.19.0 for iOS and all versions of zpi
(Zalopay in Zalo App)Description
The requestLocationPermission API allows developers to request location permission from the user. This API can also specify the desired accuracy for location retrieval. The possible permission status responses include PERMISSION_DENIED, PERMISSION_NOT_GRANTED, PERMISSION_ALWAYS, and PERMISSION_WHEN_USE, allowing developers to handle different levels of access appropriately.
Parameters
Parameters
Param | Data type | Required | Description |
---|---|---|---|
accuracy | string | No | Specifies the desired accuracy level for the location. Possible values are "high" , "medium" , and "low" . Defaults to "medium" . See details below. Only supported on ZPA |
Accuracy Levels
High Accuracy
- Description: Provides the most precise location data.
- Typical Precision: Within a few meters (1-10 meters).
- Use Cases: Navigation apps, ride-sharing services, fitness tracking, augmented reality.
- Battery Consumption: High, due to continuous use of GPS and other sensors.
Medium Accuracy
- Description: Balances precision and resource consumption.
- Typical Precision: Within 10-100 meters.
- Use Cases: Location tagging in social apps, local search, weather apps.
- Battery Consumption: Moderate, utilizing a combination of GPS, Wi-Fi, and cellular data.
Low Accuracy
- Description: Provides the least precise location data.
- Typical Precision: Greater than 100 meters.
- Use Cases: General location awareness, regional content delivery, demographic analysis.
- Battery Consumption: Low, often relying on cell tower triangulation and Wi-Fi.
Return Value
Param | Data type | Description |
---|---|---|
permissionStatus | string | When checking the location permission status before prompting the user, the following values are returned to indicate the current state: • PERMISSION_DENIED: The user has explicitly denied location permission in the past, and the permission request cannot be prompted again without guiding the user to the app's settings. Use openSystemSettings API• PERMISSION_NOT_GRANTED: The user has not yet been asked for location permission. The API will proceed to prompt the user for permission. • PERMISSION_ALWAYS: The user has granted location access always, meaning the app can access the location in the background as well as when it is in use. • PERMISSION_WHEN_USE: The user has granted location access only when the app is in use (foreground). Only for iOS |
Sample Code and Sample Return Data
Sample Request:
window.zlpSdk.Location.requestLocationPermission()
.then((response) => console.log(response))
.catch((error) => console.error(error.errorCode));
Sample Response:
{
"status": "success",
"data": { "permissionStatus": "PERMISSION_NOT_GRANTED" }
}