1e41f4b71Sopenharmony_ci# @ohos.geoLocationManager (Geolocation Manager) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **geoLocationManager** module provides location services such as Global Navigation Satellite System (GNSS)-based positioning, network positioning, geofencing, as well as geocoding and reverse geocoding. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.geoLocationManager (Geolocation Manager)](js-apis-geoLocationManager.md). 9e41f4b71Sopenharmony_ci> This module supports only the WGS-84 coordinate system. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Applying for Permissions 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ciBefore using basic location capabilities, 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 as described below. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciThe system provides the following location permissions: 16e41f4b71Sopenharmony_ci- ohos.permission.LOCATION 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci- ohos.permission.APPROXIMATELY_LOCATION 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci- ohos.permission.LOCATION_IN_BACKGROUND 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciIf your application needs to access the device location information, it must first apply for required permissions. Specifically speaking: 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciAPI versions earlier than 9: Apply for **ohos.permission.LOCATION**. 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ciAPI version 9 and later: Apply for **ohos.permission.APPROXIMATELY\_LOCATION**, or apply for **ohos.permission.APPROXIMATELY\_LOCATION** and **ohos.permission.LOCATION**. Note that **ohos.permission.LOCATION** cannot be applied for separately. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci| API Version| Location Permission| Permission Application Result| Location Accuracy| 29e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 30e41f4b71Sopenharmony_ci| Earlier than 9| ohos.permission.LOCATION | Success| Location accurate to meters| 31e41f4b71Sopenharmony_ci| 9 and later| ohos.permission.LOCATION | Failure| No location obtained| 32e41f4b71Sopenharmony_ci| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers| 33e41f4b71Sopenharmony_ci| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters| 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciTo access the device location information when running in the background, an application needs to request for the **ohos.permission.LOCATION_IN_BACKGROUND** permission or a continuous task of the background mode. In this way, the system continues to report device location information after your application moves to the background. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ciA user can grant the **ohos.permission.LOCATION_IN_BACKGROUND** permission for an application on the setting page. For details, see [ohos.permission.LOCATION_IN_BACKGROUND](../../security/AccessToken/permissions-for-all.md#ohospermissionlocation_in_background). 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ciFor details about how to request for a continuous task, see [Continuous Task](../../task-management/continuous-task.md). 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ciYou can declare the required permission in your application's configuration file. For details, see [Requesting User Authorization](../../security/AccessToken/request-user-authorization.md). 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci## Modules to Import 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci```ts 47e41f4b71Sopenharmony_ciimport { geoLocationManager } from '@kit.LocationKit'; 48e41f4b71Sopenharmony_ci``` 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci## GeoAddress 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ciGeocoding address information. 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Geocoder 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description| 57e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 58e41f4b71Sopenharmony_ci| isFromMock | Boolean | No| Yes| **true**: The geographic address is obtained from the mock reverse geocoding function.<br>**false**: The geographic address is not obtained from the mock reverse geocoding function.<br>**System API**: This is a system API.| 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci## Location 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ciLocation information. 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description| 68e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 69e41f4b71Sopenharmony_ci| isFromMock | Boolean | No| Yes| **true**: The location information is obtained from the mock location function.<br>**false**: The location information is not obtained from the location simulation function.<br>**System API**: This is a system API.| 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci## ReverseGeocodingMockInfo 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ciDefines the configuration of the mock reverse geocoding function. 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci**System API**: This is a system API. 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description| 81e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 82e41f4b71Sopenharmony_ci| location | [ReverseGeoCodeRequest](js-apis-geoLocationManager.md#reversegeocoderequest) | No| No| Latitude and longitude information.| 83e41f4b71Sopenharmony_ci| geoAddress | [GeoAddress](#geoaddress) | No| No|Geographical name.| 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci## LocationMockConfig 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ciDefines the configuration of the mock location function. 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci**System API**: This is a system API. 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description| 95e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 96e41f4b71Sopenharmony_ci| timeInterval | number | No| No| Time interval at which mock locations are reported, in seconds.| 97e41f4b71Sopenharmony_ci| locations | Array<[Location](#location)> | No| No| Array of mocked locations.| 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci## LocatingRequiredDataConfig<sup>10+</sup> 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ciDefines the configuration for obtaining the required data of the location service. 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci**System API**: This is a system API. 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description| 108e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 109e41f4b71Sopenharmony_ci| type | [LocatingRequiredDataType](#locatingrequireddatatype10) | No| No| Type of the required data.| 110e41f4b71Sopenharmony_ci| needStartScan | boolean | No| No| **true**: Scanning needs to be initiated.<br>**false**: Scanning does not need to be initiated.| 111e41f4b71Sopenharmony_ci| scanInterval | number | No| Yes| Scanning interval, in milliseconds. The specified value must be greater than **0**. The default value is **10000**.| 112e41f4b71Sopenharmony_ci| scanTimeout | number | No| Yes| Scanning timeout interval, in milliseconds. The value ranges from **0** to **600000**. The default value is **10000**.| 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci## LocatingRequiredData<sup>10+</sup> 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ciDefines the required data of the location service, including the Wi-Fi or Bluetooth scanning result. After obtaining the data, an application can use the data for services such as network positioning. 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci**System API**: This is a system API. 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description| 124e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 125e41f4b71Sopenharmony_ci| wifiData | [WifiScanInfo](#wifiscaninfo10) | No| Yes| Wi-Fi scanning result.| 126e41f4b71Sopenharmony_ci| bluetoothData | [BluetoothScanInfo](#bluetoothscaninfo10) | No| Yes| Bluetooth scanning result.| 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci## WifiScanInfo<sup>10+</sup> 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ciDefines the Wi-Fi scanning information, including the SSID, BSSID, and RSSI of the scanned Wi-Fi hotspot. 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci**System API**: This is a system API. 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description| 138e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 139e41f4b71Sopenharmony_ci| ssid | string | No| No| Service set identifier (SSID) of a Wi-Fi hotspot, in UTF-8 format.| 140e41f4b71Sopenharmony_ci| bssid | string | No| No| Base station subsystem identifier (BSSID) of a Wi-Fi hotspot.| 141e41f4b71Sopenharmony_ci| rssi | number | No| No| Received signal strength indicator (RSSI) of a Wi-Fi hotspot, in dBm.| 142e41f4b71Sopenharmony_ci| frequency | number | No| No| Frequency of a Wi-Fi hotspot.| 143e41f4b71Sopenharmony_ci| timestamp | number | No| No| Scanning timestamp.| 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci## BluetoothScanInfo<sup>10+</sup> 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ciDefines the Bluetooth scanning information. 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**System API**: This is a system API. 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description| 155e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 156e41f4b71Sopenharmony_ci| deviceName | string | No| No| Name of a Bluetooth device.| 157e41f4b71Sopenharmony_ci| macAddress | string | No| No| MAC address of a Bluetooth device.| 158e41f4b71Sopenharmony_ci| rssi | number | No| No| Signal strength of a Bluetooth device, in dBm.| 159e41f4b71Sopenharmony_ci| timestamp | number | No| No| Scanning timestamp.| 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci## LocationPrivacyType 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ciDefines the privacy statement type. 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci**System API**: This is a system API. 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci| Name| Value| Description| 170e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 171e41f4b71Sopenharmony_ci| OTHERS | 0 | Other scenarios. Reserved field.| 172e41f4b71Sopenharmony_ci| STARTUP | 1 | Privacy statement displayed in the startup wizard. The user needs to choose whether to agree with the statement.| 173e41f4b71Sopenharmony_ci| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.| 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci## LocatingRequiredDataType<sup>10+</sup> 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ciDefines the type of the required data of the location service. 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci**System API**: This is a system API. 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci| Name| Value| Description| 184e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 185e41f4b71Sopenharmony_ci| WIFI | 1 | Wi-Fi scanning information.| 186e41f4b71Sopenharmony_ci| BLUETOOTH | 2 | Bluetooth scanning information.| 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci## LocationIconStatus<sup>12+</sup> 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ciDefines the location icon status. 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci**System API**: This is a system API. 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci| Name| Value| Description| 198e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 199e41f4b71Sopenharmony_ci| LOCATING_NOT_STARTED | 0 | No location services are available and the location icon does not need to be displayed.| 200e41f4b71Sopenharmony_ci| LOCATING_STARTED | 1 | Common location is in progress, and the common location icon needs to be displayed.| 201e41f4b71Sopenharmony_ci| HD_LOCATING_STARTED | 2 | High-precision location is in progress, and the high-precision location icon needs to be displayed.| 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci## geoLocationManager.on('locatingRequiredDataChange')<sup>10+</sup> 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_cion(type: 'locatingRequiredDataChange', config: LocatingRequiredDataConfig, callback: Callback<Array<LocatingRequiredData>>): void; 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ciSubscribes to changes in the required data of the location service, including Wi-Fi and Bluetooth scanning information. An application can then determine whether to enable Wi-Fi and Bluetooth scanning based on the return result. This API uses an asynchronous callback to return the result. 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci**System API**: This is a system API. 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci**Parameters** 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci | Name| Type| Mandatory| Description| 219e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 220e41f4b71Sopenharmony_ci | type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.| 221e41f4b71Sopenharmony_ci | config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.| 222e41f4b71Sopenharmony_ci | callback | Callback<Array<[LocatingRequiredData](#locatingrequireddata10)>> | Yes| Callback used to return the data required by the location service.| 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci**Error codes** 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci| ID| Error Message| 229e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 230e41f4b71Sopenharmony_ci|201 | Permission verification failed. The application does not have the permission required to call the API. | 231e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 232e41f4b71Sopenharmony_ci|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 233e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.on('locatingRequiredDataChange')} due to limited device capabilities. | 234e41f4b71Sopenharmony_ci|3301800 | Failed to start WiFi or Bluetooth scanning. | 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci**Example** 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci ```ts 239e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 240e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit' 241e41f4b71Sopenharmony_ci let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => { 242e41f4b71Sopenharmony_ci console.log('locatingRequiredDataChange: ' + JSON.stringify(code)); 243e41f4b71Sopenharmony_ci } 244e41f4b71Sopenharmony_ci let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; 245e41f4b71Sopenharmony_ci try { 246e41f4b71Sopenharmony_ci geoLocationManager.on('locatingRequiredDataChange', config, callback); 247e41f4b71Sopenharmony_ci } catch (err) { 248e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 249e41f4b71Sopenharmony_ci } 250e41f4b71Sopenharmony_ci ``` 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci## geoLocationManager.off('locatingRequiredDataChange')<sup>10+</sup> 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_cioff(type: 'locatingRequiredDataChange', callback?: Callback<Array<LocatingRequiredData>>): void; 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ciUnsubscribes from changes in the required data of the location service and stops Wi-Fi and Bluetooth scanning. 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci**System API**: This is a system API. 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci**Parameters** 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci | Name| Type| Mandatory| Description| 268e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 269e41f4b71Sopenharmony_ci | type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.| 270e41f4b71Sopenharmony_ci | callback | Callback<Array<[LocatingRequiredData](#locatingrequireddata10)>> | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci**Error codes** 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci| ID| Error Message| 277e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 278e41f4b71Sopenharmony_ci|201 | Permission verification failed. The application does not have the permission required to call the API. | 279e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 280e41f4b71Sopenharmony_ci|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 281e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.off('locatingRequiredDataChange')} due to limited device capabilities. | 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci**Example** 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci ```ts 286e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 287e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit' 288e41f4b71Sopenharmony_ci let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => { 289e41f4b71Sopenharmony_ci console.log('locatingRequiredDataChange: ' + JSON.stringify(code)); 290e41f4b71Sopenharmony_ci } 291e41f4b71Sopenharmony_ci let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; 292e41f4b71Sopenharmony_ci try { 293e41f4b71Sopenharmony_ci geoLocationManager.on('locatingRequiredDataChange', config, callback); 294e41f4b71Sopenharmony_ci geoLocationManager.off('locatingRequiredDataChange', callback); 295e41f4b71Sopenharmony_ci } catch (err) { 296e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 297e41f4b71Sopenharmony_ci } 298e41f4b71Sopenharmony_ci ``` 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci## geoLocationManager.enableLocation 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_cienableLocation(callback: AsyncCallback<void>): void; 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ciEnables the location service. This API uses an asynchronous callback to return the result. 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci**System API**: This is a system API. 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci**Parameters** 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci | Name| Type| Mandatory| Description| 315e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 316e41f4b71Sopenharmony_ci | callback | AsyncCallback<void> | Yes| Callback used to return the result. If the location service is successfully enabled, **err** is **undefined**. Otherwise, **err** is an error object.| 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**Error codes** 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci| ID| Error Message| 323e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 324e41f4b71Sopenharmony_ci|201 | Permission verification failed. The application does not have the permission required to call the API. | 325e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 326e41f4b71Sopenharmony_ci|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 327e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.enableLocation} due to limited device capabilities. | 328e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci**Example** 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci ```ts 333e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 334e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit' 335e41f4b71Sopenharmony_ci try { 336e41f4b71Sopenharmony_ci geoLocationManager.enableLocation((err) => { 337e41f4b71Sopenharmony_ci if (err) { 338e41f4b71Sopenharmony_ci console.error('enableLocation: err=' + JSON.stringify(err)); 339e41f4b71Sopenharmony_ci } 340e41f4b71Sopenharmony_ci }); 341e41f4b71Sopenharmony_ci } catch (err) { 342e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 343e41f4b71Sopenharmony_ci } 344e41f4b71Sopenharmony_ci ``` 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci## geoLocationManager.enableLocation 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_cienableLocation(): Promise<void> 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ciEnables the location service. This API uses a promise to return the result. 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci**System API**: This is a system API. 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci**Return value** 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci | Type| Description| 362e41f4b71Sopenharmony_ci | -------- | -------- | 363e41f4b71Sopenharmony_ci | Promise<void> | Promise that returns no value.| 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci**Error codes** 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci| ID| Error Message| 370e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 371e41f4b71Sopenharmony_ci|201 | Permission verification failed. The application does not have the permission required to call the API. | 372e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 373e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.enableLocation} due to limited device capabilities. | 374e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci**Example** 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci ```ts 379e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 380e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit' 381e41f4b71Sopenharmony_ci try { 382e41f4b71Sopenharmony_ci geoLocationManager.enableLocation().then(() => { 383e41f4b71Sopenharmony_ci console.log('promise, enableLocation succeed'); 384e41f4b71Sopenharmony_ci }) 385e41f4b71Sopenharmony_ci .catch((error:BusinessError.BusinessError) => { 386e41f4b71Sopenharmony_ci console.error('promise, enableLocation: error=' + JSON.stringify(error)); 387e41f4b71Sopenharmony_ci }); 388e41f4b71Sopenharmony_ci } catch (err) { 389e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 390e41f4b71Sopenharmony_ci } 391e41f4b71Sopenharmony_ci ``` 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci## geoLocationManager.disableLocation 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_cidisableLocation(): void; 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ciDisables the location service. 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci**System API**: This is a system API. 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ci**Error codes** 406e41f4b71Sopenharmony_ci 407e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci| ID| Error Message| 410e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 411e41f4b71Sopenharmony_ci|201 | Permission verification failed. The application does not have the permission required to call the API. | 412e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 413e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.disableLocation} due to limited device capabilities. | 414e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci**Example** 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci ```ts 419e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 420e41f4b71Sopenharmony_ci try { 421e41f4b71Sopenharmony_ci geoLocationManager.disableLocation(); 422e41f4b71Sopenharmony_ci } catch (err) { 423e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 424e41f4b71Sopenharmony_ci } 425e41f4b71Sopenharmony_ci ``` 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci## geoLocationManager.enableLocationMock 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_cienableLocationMock(): void; 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_ciEnables the mock location function. 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci**System API**: This is a system API. 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci**Error codes** 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ci| ID| Error Message| 442e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 443e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 444e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.enableLocationMock} due to limited device capabilities. | 445e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 446e41f4b71Sopenharmony_ci|3301100 | The location switch is off.| 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci**Example** 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci ```ts 451e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 452e41f4b71Sopenharmony_ci try { 453e41f4b71Sopenharmony_ci geoLocationManager.enableLocationMock(); 454e41f4b71Sopenharmony_ci } catch (err) { 455e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 456e41f4b71Sopenharmony_ci } 457e41f4b71Sopenharmony_ci ``` 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ci## geoLocationManager.disableLocationMock 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_cidisableLocationMock(): void; 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ciDisables the mock location function. 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_ci**System API**: This is a system API. 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci**Error codes** 471e41f4b71Sopenharmony_ci 472e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 473e41f4b71Sopenharmony_ci 474e41f4b71Sopenharmony_ci| ID| Error Message| 475e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 476e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 477e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.disableLocationMock} due to limited device capabilities. | 478e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 479e41f4b71Sopenharmony_ci|3301100 | The location switch is off.| 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci**Example** 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci ```ts 484e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 485e41f4b71Sopenharmony_ci try { 486e41f4b71Sopenharmony_ci geoLocationManager.disableLocationMock(); 487e41f4b71Sopenharmony_ci } catch (err) { 488e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 489e41f4b71Sopenharmony_ci } 490e41f4b71Sopenharmony_ci ``` 491e41f4b71Sopenharmony_ci 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci## geoLocationManager.setMockedLocations 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_cisetMockedLocations(config: LocationMockConfig): void; 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ciSets the mock location information. The mock locations will be reported at the interval specified in this API. 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ciThis API can be invoked only after [geoLocationManager.enableLocationMock](#geolocationmanagerenablelocationmock) is called. 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci**System API**: This is a system API. 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci**Parameters** 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci | Name| Type| Mandatory| Description| 508e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 509e41f4b71Sopenharmony_ci | config | [LocationMockConfig](#locationmockconfig) | Yes| Mock location information, including the interval for reporting the mock locations and the array of the mock locations.| 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_ci**Error codes** 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ci| ID| Error Message| 516e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 517e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 518e41f4b71Sopenharmony_ci|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 519e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.setMockedLocations} due to limited device capabilities. | 520e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 521e41f4b71Sopenharmony_ci|3301100 | The location switch is off.| 522e41f4b71Sopenharmony_ci 523e41f4b71Sopenharmony_ci**Example** 524e41f4b71Sopenharmony_ci 525e41f4b71Sopenharmony_ci ```ts 526e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 527e41f4b71Sopenharmony_ci let locations:Array<geoLocationManager.Location> = [ 528e41f4b71Sopenharmony_ci {"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true}, 529e41f4b71Sopenharmony_ci {"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true}, 530e41f4b71Sopenharmony_ci {"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true}, 531e41f4b71Sopenharmony_ci {"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true}, 532e41f4b71Sopenharmony_ci {"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true} 533e41f4b71Sopenharmony_ci ]; 534e41f4b71Sopenharmony_ci let config:geoLocationManager.LocationMockConfig = {"timeInterval": 5, "locations": locations}; 535e41f4b71Sopenharmony_ci try { 536e41f4b71Sopenharmony_ci geoLocationManager.enableLocationMock(); 537e41f4b71Sopenharmony_ci geoLocationManager.setMockedLocations(config); 538e41f4b71Sopenharmony_ci } catch (err) { 539e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 540e41f4b71Sopenharmony_ci } 541e41f4b71Sopenharmony_ci ``` 542e41f4b71Sopenharmony_ci 543e41f4b71Sopenharmony_ci 544e41f4b71Sopenharmony_ci## geoLocationManager.enableReverseGeocodingMock 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_cienableReverseGeocodingMock(): void; 547e41f4b71Sopenharmony_ci 548e41f4b71Sopenharmony_ciEnables the mock reverse geocoding function. 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 551e41f4b71Sopenharmony_ci 552e41f4b71Sopenharmony_ci**System API**: This is a system API. 553e41f4b71Sopenharmony_ci 554e41f4b71Sopenharmony_ci**Error codes** 555e41f4b71Sopenharmony_ci 556e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci| ID| Error Message| 559e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 560e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 561e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.enableReverseGeocodingMock} due to limited device capabilities. | 562e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci**Example** 565e41f4b71Sopenharmony_ci 566e41f4b71Sopenharmony_ci ```ts 567e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 568e41f4b71Sopenharmony_ci try { 569e41f4b71Sopenharmony_ci geoLocationManager.enableReverseGeocodingMock(); 570e41f4b71Sopenharmony_ci } catch (err) { 571e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 572e41f4b71Sopenharmony_ci } 573e41f4b71Sopenharmony_ci ``` 574e41f4b71Sopenharmony_ci 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ci## geoLocationManager.disableReverseGeocodingMock 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_cidisableReverseGeocodingMock(): void; 579e41f4b71Sopenharmony_ci 580e41f4b71Sopenharmony_ciDisables the mock geocoding function. 581e41f4b71Sopenharmony_ci 582e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_ci**System API**: This is a system API. 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ci**Error codes** 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 589e41f4b71Sopenharmony_ci 590e41f4b71Sopenharmony_ci| ID| Error Message| 591e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 592e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 593e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.disableReverseGeocodingMock} due to limited device capabilities. | 594e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 595e41f4b71Sopenharmony_ci 596e41f4b71Sopenharmony_ci**Example** 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci ```ts 599e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 600e41f4b71Sopenharmony_ci try { 601e41f4b71Sopenharmony_ci geoLocationManager.disableReverseGeocodingMock(); 602e41f4b71Sopenharmony_ci } catch (err) { 603e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 604e41f4b71Sopenharmony_ci } 605e41f4b71Sopenharmony_ci ``` 606e41f4b71Sopenharmony_ci 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ci## geoLocationManager.setReverseGeocodingMockInfo 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_cisetReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>): void; 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ciSets information of the mock reverse geocoding function, including the mapping between a location and geographical name. If the location is contained in the configurations during reverse geocoding query, the corresponding geographical name will be returned. 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ciThis API can be invoked only after [geoLocationManager.enableReverseGeocodingMock](#geolocationmanagerenablereversegeocodingmock) is called. 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 617e41f4b71Sopenharmony_ci 618e41f4b71Sopenharmony_ci**System API**: This is a system API. 619e41f4b71Sopenharmony_ci 620e41f4b71Sopenharmony_ci**Parameters** 621e41f4b71Sopenharmony_ci 622e41f4b71Sopenharmony_ci | Name| Type| Mandatory| Description| 623e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 624e41f4b71Sopenharmony_ci | mockInfos | Array<[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)> | Yes| Array of information of the mock reverse geocoding function, including a location and a geographical name.| 625e41f4b71Sopenharmony_ci 626e41f4b71Sopenharmony_ci**Error codes** 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 629e41f4b71Sopenharmony_ci 630e41f4b71Sopenharmony_ci| ID| Error Message| 631e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 632e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 633e41f4b71Sopenharmony_ci|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 634e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.setReverseGeocodingMockInfo} due to limited device capabilities. | 635e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 636e41f4b71Sopenharmony_ci 637e41f4b71Sopenharmony_ci**Example** 638e41f4b71Sopenharmony_ci 639e41f4b71Sopenharmony_ci ```ts 640e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 641e41f4b71Sopenharmony_ci let mockInfos:Array<geoLocationManager.ReverseGeocodingMockInfo> = [ 642e41f4b71Sopenharmony_ci {"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "isFromMock": true}}, 643e41f4b71Sopenharmony_ci {"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "isFromMock": true}}, 644e41f4b71Sopenharmony_ci {"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "isFromMock": true}}, 645e41f4b71Sopenharmony_ci {"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "isFromMock": true}}, 646e41f4b71Sopenharmony_ci {"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "isFromMock": true}}, 647e41f4b71Sopenharmony_ci ]; 648e41f4b71Sopenharmony_ci try { 649e41f4b71Sopenharmony_ci geoLocationManager.enableReverseGeocodingMock(); 650e41f4b71Sopenharmony_ci geoLocationManager.setReverseGeocodingMockInfo(mockInfos); 651e41f4b71Sopenharmony_ci } catch (err) { 652e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 653e41f4b71Sopenharmony_ci } 654e41f4b71Sopenharmony_ci ``` 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ci## geoLocationManager.isLocationPrivacyConfirmed 658e41f4b71Sopenharmony_ci 659e41f4b71Sopenharmony_ciisLocationPrivacyConfirmed(type: LocationPrivacyType): boolean; 660e41f4b71Sopenharmony_ci 661e41f4b71Sopenharmony_ciChecks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications. 662e41f4b71Sopenharmony_ci 663e41f4b71Sopenharmony_ci**System API**: This is a system API. 664e41f4b71Sopenharmony_ci 665e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 666e41f4b71Sopenharmony_ci 667e41f4b71Sopenharmony_ci**Parameters** 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_ci | Name| Type| Mandatory| Description| 670e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 671e41f4b71Sopenharmony_ci | type | [LocationPrivacyType](#locationprivacytype)| Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when the location service is enabled.| 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ci**Return value** 674e41f4b71Sopenharmony_ci 675e41f4b71Sopenharmony_ci | Type| Description| 676e41f4b71Sopenharmony_ci | -------- | -------- | 677e41f4b71Sopenharmony_ci | boolean | **true**: The user agrees to the privacy statement of the location service.<br>**false**: The user does not agree to the privacy statement of the location service.| 678e41f4b71Sopenharmony_ci 679e41f4b71Sopenharmony_ci**Error codes** 680e41f4b71Sopenharmony_ci 681e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 682e41f4b71Sopenharmony_ci 683e41f4b71Sopenharmony_ci| ID| Error Message| 684e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 685e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 686e41f4b71Sopenharmony_ci|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 687e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.isLocationPrivacyConfirmed} due to limited device capabilities. | 688e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 689e41f4b71Sopenharmony_ci 690e41f4b71Sopenharmony_ci**Example** 691e41f4b71Sopenharmony_ci 692e41f4b71Sopenharmony_ci ```ts 693e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 694e41f4b71Sopenharmony_ci try { 695e41f4b71Sopenharmony_ci let isConfirmed = geoLocationManager.isLocationPrivacyConfirmed(1); 696e41f4b71Sopenharmony_ci } catch (err) { 697e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 698e41f4b71Sopenharmony_ci } 699e41f4b71Sopenharmony_ci ``` 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci 702e41f4b71Sopenharmony_ci## geoLocationManager.setLocationPrivacyConfirmStatus 703e41f4b71Sopenharmony_ci 704e41f4b71Sopenharmony_cisetLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean): void; 705e41f4b71Sopenharmony_ci 706e41f4b71Sopenharmony_ciSets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications. 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ci**System API**: This is a system API. 709e41f4b71Sopenharmony_ci 710e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS 711e41f4b71Sopenharmony_ci 712e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 713e41f4b71Sopenharmony_ci 714e41f4b71Sopenharmony_ci**Parameters** 715e41f4b71Sopenharmony_ci 716e41f4b71Sopenharmony_ci | Name| Type| Mandatory| Description| 717e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 718e41f4b71Sopenharmony_ci | type | [LocationPrivacyType](#locationprivacytype) | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when the location service is enabled.| 719e41f4b71Sopenharmony_ci | isConfirmed | boolean | Yes| **true**: The user agrees to the privacy statement of the location service.<br>**false**: The user does not agree to the privacy statement of the location service.| 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_ci**Error codes** 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 724e41f4b71Sopenharmony_ci 725e41f4b71Sopenharmony_ci| ID| Error Message| 726e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 727e41f4b71Sopenharmony_ci|201 | Permission verification failed. The application does not have the permission required to call the API. | 728e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 729e41f4b71Sopenharmony_ci|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 730e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.setLocationPrivacyConfirmStatus} due to limited device capabilities. | 731e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 732e41f4b71Sopenharmony_ci 733e41f4b71Sopenharmony_ci**Example** 734e41f4b71Sopenharmony_ci 735e41f4b71Sopenharmony_ci ```ts 736e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 737e41f4b71Sopenharmony_ci try { 738e41f4b71Sopenharmony_ci geoLocationManager.setLocationPrivacyConfirmStatus(1, true); 739e41f4b71Sopenharmony_ci } catch (err) { 740e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 741e41f4b71Sopenharmony_ci } 742e41f4b71Sopenharmony_ci ``` 743e41f4b71Sopenharmony_ci 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci## geoLocationManager.getLocatingRequiredData<sup>10+</sup> 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_cigetLocatingRequiredData(config: LocatingRequiredDataConfig): Promise<Array<LocatingRequiredData>>; 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ciObtains the required data of the location service. This API uses a promise to return the result. 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci**System API**: This is a system API. 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci**Parameters** 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci | Name| Type| Mandatory| Description| 760e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 761e41f4b71Sopenharmony_ci | config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.| 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci**Return value** 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_ci | Type| Description| 766e41f4b71Sopenharmony_ci | -------- | -------- | 767e41f4b71Sopenharmony_ci | Promise<Array<[LocatingRequiredData](#locatingrequireddata10)>> | Promise used to return the required data for the location service, such as the Wi-Fi and Bluetooth scanning information.| 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ci**Error codes** 770e41f4b71Sopenharmony_ci 771e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_ci| ID| Error Message| 774e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 775e41f4b71Sopenharmony_ci|201 | Permission verification failed. The application does not have the permission required to call the API. | 776e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 777e41f4b71Sopenharmony_ci|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 778e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.getLocatingRequiredData} due to limited device capabilities. | 779e41f4b71Sopenharmony_ci|3301800 | Failed to start WiFi or Bluetooth scanning. | 780e41f4b71Sopenharmony_ci 781e41f4b71Sopenharmony_ci**Example** 782e41f4b71Sopenharmony_ci 783e41f4b71Sopenharmony_ci ```ts 784e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 785e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit' 786e41f4b71Sopenharmony_ci let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; 787e41f4b71Sopenharmony_ci try { 788e41f4b71Sopenharmony_ci geoLocationManager.getLocatingRequiredData(config).then((result) => { 789e41f4b71Sopenharmony_ci console.log('getLocatingRequiredData return: ' + JSON.stringify(result)); 790e41f4b71Sopenharmony_ci }) 791e41f4b71Sopenharmony_ci .catch((error:BusinessError.BusinessError) => { 792e41f4b71Sopenharmony_ci console.error('promise, getLocatingRequiredData: error=' + JSON.stringify(error)); 793e41f4b71Sopenharmony_ci }); 794e41f4b71Sopenharmony_ci } catch (err) { 795e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 796e41f4b71Sopenharmony_ci } 797e41f4b71Sopenharmony_ci ``` 798e41f4b71Sopenharmony_ci 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ci## geoLocationManager.on('locationIconStatusChange')<sup>12+</sup> 801e41f4b71Sopenharmony_ci 802e41f4b71Sopenharmony_cion(type: 'locationIconStatusChange', callback: Callback<LocationIconStatus>): void; 803e41f4b71Sopenharmony_ci 804e41f4b71Sopenharmony_ciSubscribes to status changes of the location icon. This API uses an asynchronous callback to return the result. 805e41f4b71Sopenharmony_ci 806e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 807e41f4b71Sopenharmony_ci 808e41f4b71Sopenharmony_ci**System API**: This is a system API. 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ci**Parameters** 811e41f4b71Sopenharmony_ci 812e41f4b71Sopenharmony_ci | Name| Type| Mandatory| Description| 813e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 814e41f4b71Sopenharmony_ci | type | string | Yes| Event type. Event type. The value **locationIconStatusChange** indicates status changes of the location icon.| 815e41f4b71Sopenharmony_ci | callback | Callback<[LocationIconStatus](#locationiconstatus12)> | Yes| Callback used to return the location icon status.| 816e41f4b71Sopenharmony_ci 817e41f4b71Sopenharmony_ci**Error codes** 818e41f4b71Sopenharmony_ci 819e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_ci| ID| Error Message| 822e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 823e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 824e41f4b71Sopenharmony_ci|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 825e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.on('locationIconStatusChange')} due to limited device capabilities. | 826e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 827e41f4b71Sopenharmony_ci 828e41f4b71Sopenharmony_ci**Example** 829e41f4b71Sopenharmony_ci 830e41f4b71Sopenharmony_ci ```ts 831e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 832e41f4b71Sopenharmony_ci let callback = (code: geoLocationManager.LocationIconStatus):void => { 833e41f4b71Sopenharmony_ci console.log('LocationIconStatus: ' + JSON.stringify(code)); 834e41f4b71Sopenharmony_ci } 835e41f4b71Sopenharmony_ci try { 836e41f4b71Sopenharmony_ci geoLocationManager.on('locationIconStatusChange', callback); 837e41f4b71Sopenharmony_ci } catch (err) { 838e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 839e41f4b71Sopenharmony_ci } 840e41f4b71Sopenharmony_ci ``` 841e41f4b71Sopenharmony_ci 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_ci## geoLocationManager.off('locationIconStatusChange')<sup>12+</sup> 844e41f4b71Sopenharmony_ci 845e41f4b71Sopenharmony_cioff(type: 'locationIconStatusChange', callback?: Callback<LocationIconStatus>): void; 846e41f4b71Sopenharmony_ci 847e41f4b71Sopenharmony_ciUnsubscribes from status changes of the location icon. 848e41f4b71Sopenharmony_ci 849e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 850e41f4b71Sopenharmony_ci 851e41f4b71Sopenharmony_ci**System API**: This is a system API. 852e41f4b71Sopenharmony_ci 853e41f4b71Sopenharmony_ci**Parameters** 854e41f4b71Sopenharmony_ci 855e41f4b71Sopenharmony_ci | Name| Type| Mandatory| Description| 856e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 857e41f4b71Sopenharmony_ci | type | string | Yes| Event type. Event type. The value **locationIconStatusChange** indicates status changes of the location icon.| 858e41f4b71Sopenharmony_ci | callback | Callback<[LocationIconStatus](#locationiconstatus12)> | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 859e41f4b71Sopenharmony_ci 860e41f4b71Sopenharmony_ci**Error codes** 861e41f4b71Sopenharmony_ci 862e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 863e41f4b71Sopenharmony_ci 864e41f4b71Sopenharmony_ci| ID| Error Message| 865e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 866e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 867e41f4b71Sopenharmony_ci|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 868e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.off('locationIconStatusChange')} due to limited device capabilities. | 869e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 870e41f4b71Sopenharmony_ci 871e41f4b71Sopenharmony_ci**Example** 872e41f4b71Sopenharmony_ci 873e41f4b71Sopenharmony_ci ```ts 874e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 875e41f4b71Sopenharmony_ci let callback = (code: geoLocationManager.LocationIconStatus):void => { 876e41f4b71Sopenharmony_ci console.log('LocationIconStatus: ' + JSON.stringify(code)); 877e41f4b71Sopenharmony_ci } 878e41f4b71Sopenharmony_ci try { 879e41f4b71Sopenharmony_ci geoLocationManager.on('locationIconStatusChange', callback); 880e41f4b71Sopenharmony_ci geoLocationManager.off('locationIconStatusChange', callback); 881e41f4b71Sopenharmony_ci } catch (err) { 882e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 883e41f4b71Sopenharmony_ci } 884e41f4b71Sopenharmony_ci ``` 885e41f4b71Sopenharmony_ci 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_ci## geoLocationManager.getLocationIconStatus<sup>12+</sup> 888e41f4b71Sopenharmony_ci 889e41f4b71Sopenharmony_cigetLocationIconStatus(): LocationIconStatus; 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ciObtains the current location icon status. 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Location.Location.Core 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci**System API**: This is a system API. 896e41f4b71Sopenharmony_ci 897e41f4b71Sopenharmony_ci**Return value** 898e41f4b71Sopenharmony_ci 899e41f4b71Sopenharmony_ci | Type| Description| 900e41f4b71Sopenharmony_ci | -------- | -------- | 901e41f4b71Sopenharmony_ci | [LocationIconStatus](#locationiconstatus12) | Location icon status.| 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_ci**Error codes** 904e41f4b71Sopenharmony_ci 905e41f4b71Sopenharmony_ciFor details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 906e41f4b71Sopenharmony_ci 907e41f4b71Sopenharmony_ci| ID| Error Message| 908e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 909e41f4b71Sopenharmony_ci|202 | Permission verification failed. A non-system application calls a system API. | 910e41f4b71Sopenharmony_ci|801 | Capability not supported. Failed to call ${geoLocationManager.getLocationIconStatus} due to limited device capabilities. | 911e41f4b71Sopenharmony_ci|3301000 | The location service is unavailable. | 912e41f4b71Sopenharmony_ci 913e41f4b71Sopenharmony_ci**Example** 914e41f4b71Sopenharmony_ci 915e41f4b71Sopenharmony_ci ```ts 916e41f4b71Sopenharmony_ci import { geoLocationManager } from '@kit.LocationKit'; 917e41f4b71Sopenharmony_ci try { 918e41f4b71Sopenharmony_ci let iconStatus = geoLocationManager.getLocationIconStatus(); 919e41f4b71Sopenharmony_ci } catch (err) { 920e41f4b71Sopenharmony_ci console.error("errCode:" + JSON.stringify(err)); 921e41f4b71Sopenharmony_ci } 922e41f4b71Sopenharmony_ci ``` 923