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 that is enabled. For details, see [MDM Kit Development](../../mdm/mdm-kit-guide.md). 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 a 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'; 53 54let wantTemp: Want = { 55 bundleName: 'com.example.myapplication', 56 abilityName: 'EntryAbility', 57}; 58 59try { 60 locationManager.setLocationPolicy(wantTemp, locationManager.LocationPolicy.DISALLOW_LOCATION_SERVICE); 61 console.info(`Succeeded in setting location patch tag.`); 62} catch(err) { 63 console.error(`Failed to get location patch tag. Code: ${err.code}, message: ${err.message}`); 64} 65``` 66## locationManager.getLocationPolicy 67 68getLocationPolicy(admin: Want): LocationPolicy 69 70Queries the location service policy. 71 72**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_LOCATION 73 74**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 75 76 77**Parameters** 78 79| Name | Type | Mandatory | Description | 80| -------- | ---------------------------------------- | ---- | ------------------------------- | 81| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 82 83**Return value** 84 85| Type | Description | 86| --------------------------------- | ---------------------------------------------------- | 87| [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.| 88 89**Error codes** 90 91For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 92 93| ID| Error Message | 94| ------- | ---------------------------------------------------------------------------- | 95| 9200001 | The application is not an administrator application of the device. | 96| 9200002 | The administrator application does not have permission to manage the device. | 97| 201 | Permission verification failed. The application does not have the permission required to call the API. | 98| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 99 100**Example** 101 102```ts 103import { Want } from '@kit.AbilityKit'; 104 105let wantTemp: Want = { 106 bundleName: 'com.example.myapplication', 107 abilityName: 'EntryAbility', 108}; 109 110try { 111 let result: locationManager.LocationPolicy = locationManager.getLocationPolicy(wantTemp); 112 console.info(`Succeeded in getting location policy. policy: ${result}`); 113} catch(err) { 114 console.error(`Failed to get device encryption status. Code: ${err.code}, message: ${err.message}`); 115} 116``` 117 118## LocationPolicy 119 120Enumerates the location service policies. 121 122**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 123 124 125**Model restriction**: This API can be used only in the stage model. 126 127| Name | Value | Description | 128| ----------------------------| ----| ------------------------------- | 129| DEFAULT_LOCATION_SERVICE | 0 | Default policy.| 130| DISALLOW_LOCATION_SERVICE | 1 | The location service is disabled.| 131| FORCE_OPEN_LOCATION_SERVICE | 2 | The location service is forcibly enabled.| 132