1e41f4b71Sopenharmony_ci# @ohos.enterprise.locationManager (Location Service Management)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **locationManager** module provides location service management capabilities for devices, including setting and obtaining the location service policy.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> The APIs of this module can be used only in the stage model.
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci> The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is enabled.
12e41f4b71Sopenharmony_ci> 
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci## Modules to Import
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci```ts
17e41f4b71Sopenharmony_ciimport { locationManager } from '@kit.MDMKit';
18e41f4b71Sopenharmony_ci```
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci## locationManager.setLocationPolicy
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_cisetLocationPolicy(admin: Want, policy: LocationPolicy): void
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ciSets the location service policy. This API returns the result synchronously. If the operation fails, an exception will be thrown.
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_LOCATION
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**Parameters**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory  | Description     |
34e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- |
35e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes   | Device administrator application.|
36e41f4b71Sopenharmony_ci| policy | [LocationPolicy](#locationpolicy) | Yes   | Location service policy to set. The value can be any of the following:<br>- **0**: The default policy is used.<br>- **1**: The location service is disabled.<br>- **2**: The location service is forcibly enabled.|
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Error codes**
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci| ID| Error Message                                                                    |
43e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
44e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. |
45e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. |
46e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
47e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**Example**
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci```ts
52e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
53e41f4b71Sopenharmony_ciimport { locationManager } from '@kit.MDMKit';
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_cilet wantTemp: Want = {
56e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
57e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
58e41f4b71Sopenharmony_ci};
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_citry {
61e41f4b71Sopenharmony_ci    locationManager.setLocationPolicy(wantTemp, locationManager.LocationPolicy.DISALLOW_LOCATION_SERVICE);
62e41f4b71Sopenharmony_ci    console.info(`Succeeded in setting location patch tag.`);
63e41f4b71Sopenharmony_ci} catch(err) {
64e41f4b71Sopenharmony_ci    console.error(`Failed to get location patch tag. Code: ${err.code}, message: ${err.message}`);
65e41f4b71Sopenharmony_ci}
66e41f4b71Sopenharmony_ci```
67e41f4b71Sopenharmony_ci## locationManager.getLocationPolicy
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_cigetLocationPolicy(admin: Want): LocationPolicy
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ciObtains the location service policy. This API returns the result synchronously. If the operation is successful, the location service policy is returned. If the operation fails, an exception will be thrown.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_LOCATION
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**Parameters**
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description                      |
81e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- |
82e41f4b71Sopenharmony_ci| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Return value**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci| Type                             | Description                                                |
87e41f4b71Sopenharmony_ci| --------------------------------- | ---------------------------------------------------- |
88e41f4b71Sopenharmony_ci| [LocationPolicy](#locationpolicy) | Location service policy obtained.|
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**Error codes**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci| ID| Error Message                                                                      |
95e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
96e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. |
97e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. |
98e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
99e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci**Example**
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci```ts
104e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
105e41f4b71Sopenharmony_ciimport { locationManager } from '@kit.MDMKit';
106e41f4b71Sopenharmony_cilet wantTemp: Want = {
107e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
108e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
109e41f4b71Sopenharmony_ci};
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_citry {
112e41f4b71Sopenharmony_ci    let result: locationManager.LocationPolicy = locationManager.getLocationPolicy(wantTemp);
113e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting location policy. policy: ${result}`);
114e41f4b71Sopenharmony_ci} catch(err) {
115e41f4b71Sopenharmony_ci    console.error(`Failed to get device encryption status. Code: ${err.code}, message: ${err.message}`);
116e41f4b71Sopenharmony_ci}
117e41f4b71Sopenharmony_ci```
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci## LocationPolicy
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ciEnumerates the location service policies.
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci| Name                       | Value | Description   |
129e41f4b71Sopenharmony_ci| ----------------------------| ----| ------------------------------- |
130e41f4b71Sopenharmony_ci| DEFAULT_LOCATION_SERVICE    | 0   | Default policy.|
131e41f4b71Sopenharmony_ci| DISALLOW_LOCATION_SERVICE | 1   | The location service is disabled.|
132e41f4b71Sopenharmony_ci| FORCE_OPEN_LOCATION_SERVICE | 2   | The location service is forcibly enabled.|
133