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