harmony 鸿蒙Applying for Location Permissions (ArkTS)

  • 2025-06-06
  • 浏览 (3)

Applying for Location Permissions (ArkTS)

Scenario

Before using the capabilities provided by Location Kit, check whether your application has been granted the permission to access the device location information. If not, your application needs to obtain the permission from the user.

The system provides the following location permission:

  • ohos.permission.LOCATION: used to obtain location accurate to meters.

  • ohos.permission.APPROXIMATELY_LOCATION: used to obtain location accurate to 5 kilometers.

  • ohos.permission.LOCATION_IN_BACKGROUND: used to obtain location while the application is running at the background.

For details about the permissions required for each API of Location Kit, see Location Kit.

How to Develop

  1. Declare the required permission in your application’s configuration file. For details, see Requesting User Authorization.

  2. If your application needs to access the device location when running in the foreground, declare the location permission as described in the following table.

Permission Declarable or Not Location Accuracy
ohos.permission.APPROXIMATELY_LOCATION Yes Location accurate to 5 kilometers.
ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION Yes Location accurate to meters.
  1. If your application needs to access the device location when running in the background, declare the location permission as follows:

If your application needs to access the device location when running in the background, also request for a continuous task of the LOCATION type in addition to the permission declared in step 2.

For details about how to request for a continuous task, see Continuous Task and Continuous Task Development Example.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Location Kit

harmony 鸿蒙Samples

harmony 鸿蒙FenceExtensionAbility

harmony 鸿蒙Geocoding and Reverse Geocoding (ArkTS)

harmony 鸿蒙Geofencing (ArkTS)

harmony 鸿蒙Obtaining Device Location Information (C/C++)

harmony 鸿蒙Obtaining Device Location Information (ArkTS)

harmony 鸿蒙Introduction to Location Kit

0  赞