1# @ohos.geoLocationManager (Geolocation Manager) 2 3The **geoLocationManager** module provides location services such as Global Navigation Satellite System (GNSS)-based positioning, network positioning, geofencing, as well as geocoding and reverse geocoding. 4 5> **NOTE** 6> 7> 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. 8 9## Applying for Permissions 10 11Before 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. 12 13The system provides the following location permissions: 14- ohos.permission.LOCATION 15 16- ohos.permission.APPROXIMATELY_LOCATION 17 18- ohos.permission.LOCATION_IN_BACKGROUND 19 20If your application needs to access the device location information, it must first apply for required permissions. Specifically speaking: 21 22API versions earlier than 9: Apply for **ohos.permission.LOCATION**. 23 24API 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. 25 26| API Version| Location Permission| Permission Application Result| Location Accuracy| 27| -------- | -------- | -------- | -------- | 28| Earlier than 9| ohos.permission.LOCATION | Success| Location accurate to meters| 29| 9 and later| ohos.permission.LOCATION | Failure| No location obtained| 30| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers| 31| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters| 32 33If your application needs to access the device location information when running in the background, it must be configured to be able to run in the background and be granted the **ohos.permission.LOCATION_IN_BACKGROUND** permission. In this way, the system continues to report device location information after your application moves to the background. 34 35You can declare the required permission in your application's configuration file. For details, see [Access Control (Permission) Development](../../security/accesstoken-guidelines.md). 36 37 38## Modules to Import 39 40```ts 41import geoLocationManager from '@ohos.geoLocationManager'; 42``` 43 44 45## ReverseGeoCodeRequest 46 47Defines a reverse geocoding request. 48 49**System capability**: SystemCapability.Location.Location.Geocoder 50 51| Name| Type| Readable| Writable| Description| 52| -------- | -------- | -------- | -------- | -------- | 53| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.| 54| latitude | number | Yes| Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.| 55| longitude | number | Yes| Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.| 56| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The specified value must be greater than or equal to **0**. A value smaller than **10** is recommended.| 57 58 59## GeoCodeRequest 60 61Defines a geocoding request. 62 63**System capability**: SystemCapability.Location.Location.Geocoder 64 65| Name| Type| Readable|Writable| Description| 66| -------- | -------- | -------- | -------- | -------- | 67| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.| 68| description | string | Yes| Yes| Location description, for example, **No. xx, xx Road, Pudong New District, Shanghai**.| 69| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The specified value must be greater than or equal to **0**. A value smaller than **10** is recommended.| 70| minLatitude | number | Yes| Yes| Minimum latitude. This parameter is used with **minLongitude**, **maxLatitude**, and **maxLongitude** to specify the latitude and longitude ranges. The value ranges from **-90** to **90**.| 71| minLongitude | number | Yes| Yes| Minimum longitude. The value ranges from **-180** to **180**.| 72| maxLatitude | number | Yes| Yes| Maximum latitude. The value ranges from **-90** to **90**.| 73| maxLongitude | number | Yes| Yes| Maximum longitude. The value ranges from **-180** to **180**.| 74 75 76## GeoAddress 77 78Defines a geographic location. 79 80**System capability**: SystemCapability.Location.Location.Geocoder 81 82| Name| Type| Readable|Writable| Description| 83| -------- | -------- | -------- | -------- | -------- | 84| latitude | number | Yes| No | Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.| 85| longitude | number | Yes| No | Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.| 86| locale | string | Yes| No | Language used for the location description. **zh** indicates Chinese, and **en** indicates English.| 87| placeName | string | Yes| No | Landmark of the location.| 88| countryCode | string | Yes| No | Country code.| 89| countryName | string| Yes| No| Country name.| 90| administrativeArea | string | Yes| No| Administrative region name.| 91| subAdministrativeArea | string | Yes| No| Sub-administrative region name.| 92| locality | string | Yes| No| Locality information.| 93| subLocality | string | Yes| No| Sub-locality information.| 94| roadName | string | Yes| No|Road name.| 95| subRoadName | string | Yes| No| Auxiliary road information.| 96| premises | string| Yes| No|House information.| 97| postalCode | string | Yes| No| Postal code.| 98| phoneNumber | string | Yes| No| Phone number.| 99| addressUrl | string | Yes| No| Website URL.| 100| descriptions | Array<string> | Yes| No| Additional descriptions.| 101| descriptionsSize | number | Yes| No| Total number of additional descriptions. The specified value must be greater than or equal to **0**. A value smaller than **10** is recommended.| 102| isFromMock | Boolean | Yes| No| Whether the geographical name is from the mock reverse geocoding function.<br>**System API**: This is a system API.| 103 104 105## LocationRequest 106 107Defines a location request. 108 109**System capability**: SystemCapability.Location.Location.Core 110 111| Name| Type| Readable|Writable| Description| 112| -------- | -------- | -------- | -------- | -------- | 113| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request. This parameter is effective only when **scenario** is set to **UNSET**. If this parameter and **scenario** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestPriority](#locationrequestpriority).| 114| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request. The **priority** parameter is effective only when this parameter is set to **UNSET**. If this parameter and **priority** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestScenario](#locationrequestscenario).| 115| timeInterval | number | Yes| Yes| Time interval at which location information is reported, in seconds. The specified value must be greater than or equal to **0**. The default value is **1**.| 116| distanceInterval | number | Yes| Yes| Distance interval at which location information is reported, in meters. The specified value must be greater than or equal to **0**. The default value is **0**.| 117| maxAccuracy | number | Yes| Yes| Location accuracy, in meters. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled. The specified value must be greater than or equal to **0**. The default value is **0**.| 118 119 120## CurrentLocationRequest 121 122Defines the current location request. 123 124**System capability**: SystemCapability.Location.Location.Core 125 126| Name| Type| Readable|Writable| Description| 127| -------- | -------- | -------- | -------- | -------- | 128| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request. This parameter is effective only when **scenario** is set to **UNSET**. If this parameter and **scenario** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestPriority](#locationrequestpriority).| 129| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request. The **priority** parameter is effective only when this parameter is set to **UNSET**. If this parameter and **priority** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestScenario](#locationrequestscenario).| 130| maxAccuracy | number | Yes| Yes| Location accuracy, in meters. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled. The specified value must be greater than or equal to **0**. The default value is **0**.| 131| timeoutMs | number | Yes| Yes| Timeout duration, in milliseconds. The minimum value is **1000**. The specified value must be greater than or equal to **1000**.| 132 133 134## SatelliteStatusInfo 135 136Defines the satellite status information. 137 138**System capability**: SystemCapability.Location.Location.Gnss 139 140| Name| Type| Readable|Writable| Description| 141| -------- | -------- | -------- | -------- | -------- | 142| satellitesNumber | number | Yes| No| Number of satellites. The specified value must be greater than or equal to **0**.| 143| satelliteIds | Array<number> | Yes| No| Array of satellite IDs. The specified value must be greater than or equal to **0**.| 144| carrierToNoiseDensitys | Array<number> | Yes| No| Carrier-to-noise density ratio, that is, **cn0**. The specified value must be greater than **0**.| 145| altitudes | Array<number> | Yes| No| Satellite altitude angle information. The value ranges from **-90** to **90**, in degrees.| 146| azimuths | Array<number> | Yes| No| Azimuth information. The value ranges from **0** to **360**, in degrees.| 147| carrierFrequencies | Array<number> | Yes| No| Carrier frequency, in Hz. The specified value must be greater than or equal to **0**.| 148 149 150## CachedGnssLocationsRequest 151 152Defines a request for reporting cached GNSS locations. 153 154**System capability**: SystemCapability.Location.Location.Gnss 155 156| Name| Type| Readable|Writable| Description| 157| -------- | -------- | -------- | -------- | -------- | 158| reportingPeriodSec | number | Yes| Yes| Interval for reporting the cached GNSS locations, in milliseconds. The specified value must be greater than **0**.| 159| wakeUpCacheQueueFull | boolean | Yes| Yes | **true**: reports the cached GNSS locations to the application when the cache queue is full.<br>**false**: discards the cached GNSS locations when the cache queue is full.| 160 161 162## Geofence 163 164Defines a GNSS geofence. Currently, only circular geofences are supported. 165 166**System capability**: SystemCapability.Location.Location.Geofence 167 168| Name| Type| Readable|Writable| Description| 169| -------- | -------- | -------- | -------- | -------- | 170| latitude | number | Yes| Yes|Latitude information. The value ranges from **-90** to **90**.| 171| longitude | number | Yes|Yes| Longitude information. The value ranges from **-180** to **180**.| 172| radius | number | Yes|Yes| Radius of a circular geofence, in meters. The specified value must be greater than **0**.| 173| expiration | number | Yes|Yes| Expiration period of a geofence, in milliseconds. The specified value must be greater than **0**.| 174 175 176## GeofenceRequest 177 178Defines a GNSS geofencing request. 179 180**System capability**: SystemCapability.Location.Location.Geofence 181 182| Name| Type| Readable|Writable| Description| 183| -------- | -------- | -------- | -------- | -------- | 184| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes | Location scenario.| 185| geofence | [Geofence](#geofence)| Yes| Yes | Geofence information.| 186 187 188## LocationCommand 189 190Defines an extended command. 191 192**System capability**: SystemCapability.Location.Location.Core 193 194| Name| Type| Readable|Writable| Description| 195| -------- | -------- | -------- | -------- | -------- | 196| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes | Location scenario.| 197| command | string | Yes| Yes | Extended command, in the string format.| 198 199 200## Location 201 202Defines a location. 203 204**System capability**: SystemCapability.Location.Location.Core 205 206| Name| Type| Readable|Writable| Description| 207| -------- | -------- | -------- | -------- | -------- | 208| latitude | number| Yes| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.| 209| longitude | number| Yes| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.| 210| altitude | number | Yes| No| Location altitude, in meters.| 211| accuracy | number | Yes| No| Location accuracy, in meters.| 212| speed | number | Yes| No|Speed, in m/s.| 213| timeStamp | number | Yes| No| Location timestamp in the UTC format.| 214| direction | number | Yes| No| Direction information. The value ranges from **0** to **360**, in degrees.| 215| timeSinceBoot | number | Yes| No| Location timestamp since boot.| 216| additions | Array<string> | Yes| No| Additional description.| 217| additionSize | number | Yes| No| Number of additional descriptions. The specified value must be greater than or equal to **0**. | 218| isFromMock | Boolean | Yes| No| Whether the location information is from the mock location function.<br>**System API**: This is a system API.| 219 220 221## ReverseGeocodingMockInfo 222 223Defines the configuration of the mock reverse geocoding function. 224 225**System capability**: SystemCapability.Location.Location.Core 226 227**System API**: This is a system API. 228 229| Name| Type| Readable|Writable| Description| 230| -------- | -------- | -------- | -------- | -------- | 231| location | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Yes| Latitude and longitude information.| 232| geoAddress | [GeoAddress](#geoaddress) | Yes| Yes|Geographical name.| 233 234 235## LocationMockConfig 236 237Defines the configuration of the mock location function. 238 239**System capability**: SystemCapability.Location.Location.Core 240 241**System API**: This is a system API. 242 243| Name| Type| Readable|Writable| Description| 244| -------- | -------- | -------- | -------- | -------- | 245| timeInterval | number | Yes| Yes| Time interval at which mock locations are reported, in seconds.| 246| locations | Array<[Location](#location)> | Yes| Yes| Array of mocked locations.| 247 248 249## CountryCode 250 251Defines the country code information. 252 253**System capability**: SystemCapability.Location.Location.Core 254 255| Name| Type| Readable|Writable| Description| 256| -------- | -------- | -------- | -------- | -------- | 257| country | string | Yes| No| Country code.| 258| type | [CountryCodeType](#countrycodetype) | Yes| No| Country code source.| 259 260 261## LocatingRequiredDataConfig<sup>10+</sup> 262 263Defines the configuration for obtaining the required data of the location service. 264 265**System capability**: SystemCapability.Location.Location.Core 266 267**System API**: This is a system API. 268 269| Name| Type| Readable|Writable| Description| 270| -------- | -------- | -------- | -------- | -------- | 271| type | [LocatingRequiredDataType](#locatingrequireddatatype10) | Yes| Yes| Type of the required data.| 272| needStartScan | boolean | Yes| Yes| Whether to initiate scanning.| 273| scanInterval | number | Yes| Yes| Scanning interval, in milliseconds. The specified value must be greater than **0**. The default value is **10000**.| 274| scanTimeout | number | Yes| Yes| Scanning timeout interval, in milliseconds. The value ranges from **0** to **600000**. The default value is **10000**.| 275 276 277## LocatingRequiredData<sup>10+</sup> 278 279Defines 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. 280 281**System capability**: SystemCapability.Location.Location.Core 282 283**System API**: This is a system API. 284 285| Name| Type| Readable|Writable| Description| 286| -------- | -------- | -------- | -------- | -------- | 287| wifiData | [WifiScanInfo](#wifiscaninfo10) | Yes| No| Wi-Fi scanning result.| 288| bluetoothData | [BluetoothScanInfo](#bluetoothscaninfo10) | Yes| No| Bluetooth scanning result.| 289 290 291## WifiScanInfo<sup>10+</sup> 292 293Defines the Wi-Fi scanning information, including the SSID, BSSID, and RSSI of the scanned Wi-Fi hotspot. 294 295**System capability**: SystemCapability.Location.Location.Core 296 297**System API**: This is a system API. 298 299| Name| Type| Readable|Writable| Description| 300| -------- | -------- | -------- | -------- | -------- | 301| ssid | string | Yes| No| Service set identifier (SSID) of a Wi-Fi hotspot, in UTF-8 format.| 302| bssid | string | Yes| No| Base station subsystem identifier (BSSID) of a Wi-Fi hotspot.| 303| rssi | number | Yes| No| Received signal strength indicator (RSSI) of a Wi-Fi hotspot, in dBm.| 304| frequency | number | Yes| No| Frequency of a Wi-Fi hotspot.| 305| timestamp | number | Yes| No| Scanning timestamp.| 306 307 308## BluetoothScanInfo<sup>10+</sup> 309 310Defines the Bluetooth scanning information. 311 312**System capability**: SystemCapability.Location.Location.Core 313 314**System API**: This is a system API. 315 316| Name| Type| Readable|Writable| Description| 317| -------- | -------- | -------- | -------- | -------- | 318| deviceName | string | Yes| No| Name of a Bluetooth device.| 319| macAddress | string | Yes| No| MAC address of a Bluetooth device.| 320| rssi | number | Yes| No| Signal strength of a Bluetooth device, in dBm.| 321| timestamp | number | Yes| No| Scanning timestamp.| 322 323 324## LocationRequestPriority 325 326Sets the priority of the location request. 327 328**System capability**: SystemCapability.Location.Location.Core 329 330| Name| Value| Description| 331| -------- | -------- | -------- | 332| UNSET | 0x200 | Priority unspecified.<br>If this option is used, [LocationRequestPriority](#locationrequestpriority) is invalid.| 333| ACCURACY | 0x201 | Location accuracy.<br>This policy mainly uses the GNSS positioning technology. In an open area, the technology can achieve the meter-level location accuracy, depending on the hardware performance of the device. However, in a shielded environment, the location accuracy may significantly decrease.| 334| LOW_POWER | 0x202 | Power efficiency.<br>This policy mainly uses the base station positioning, WLAN positioning, and Bluetooth positioning technologies to obtain device location in both indoor and outdoor scenarios. The location accuracy depends on the distribution of surrounding base stations, visible WLANs, and Bluetooth devices and therefore may fluctuate greatly. This policy is recommended and can reduce power consumption when your application does not require high location accuracy or when base stations, visible WLANs, and Bluetooth devices are densely distributed.| 335| FIRST_FIX | 0x203 | Fast location preferred. Use this option if you want to obtain a location as fast as possible.<br>This policy uses the GNSS positioning, base station positioning, WLAN positioning, and Bluetooth positioning technologies simultaneously to obtain the device location in both the indoor and outdoor scenarios. When all positioning technologies provide a location result, the system provides the most accurate location result for your application. It can lead to significant hardware resource consumption and power consumption.| 336 337 338## LocationRequestScenario 339 340 Sets the scenario of the location request. 341 342**System capability**: SystemCapability.Location.Location.Core 343 344| Name| Value| Description| 345| -------- | -------- | -------- | 346| UNSET | 0x300 | Scenario unspecified.<br>If this option is used, [LocationRequestScenario](#locationrequestscenario) is invalid.| 347| NAVIGATION | 0x301 | Navigation.<br>This option is applicable when your application needs to obtain the real-time location of a mobile device outdoors, such as navigation for driving or walking.<br>In this scenario, GNSS positioning is used to provide location services to ensure the optimal location accuracy of the system.<br>The location result is reported at a minimum interval of 1 second by default.| 348| TRAJECTORY_TRACKING | 0x302 | Trajectory tracking.<br>This option is applicable when your application needs to record user trajectories, for example, the track recording function of sports applications. In this scenario, the GNSS positioning technology is mainly used to ensure the location accuracy.<br>The location result is reported at a minimum interval of 1 second by default.| 349| CAR_HAILING | 0x303 | Ride hailing.<br>This option is applicable when your application needs to obtain the current location of a user who is hailing a taxi.<br>The location result is reported at a minimum interval of 1 second by default.| 350| DAILY_LIFE_SERVICE | 0x304 | Daily life services.<br>This option is applicable when your application only needs the approximate user location for recommendations and push notifications in scenarios such as when the user is browsing news, shopping online, and ordering food.<br>The location result is reported at a minimum interval of 1 second by default.| 351| NO_POWER | 0x305 | Power efficiency. Your application does not proactively start the location service. When responding to another application requesting the same location service, the system marks a copy of the location result to your application. In this way, your application will not consume extra power for obtaining the user location.| 352 353 354## LocationPrivacyType 355 356Defines the privacy statement type. 357 358**System capability**: SystemCapability.Location.Location.Core 359 360**System API**: This is a system API. 361 362| Name| Value| Description| 363| -------- | -------- | -------- | 364| OTHERS | 0 | Other scenarios. Reserved field.| 365| STARTUP | 1 | Privacy statement displayed in the startup wizard. The user needs to choose whether to agree with the statement.| 366| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.| 367 368 369## CountryCodeType 370 371Defines the country code source type. 372 373**System capability**: SystemCapability.Location.Location.Core 374 375| Name| Value| Description| 376| -------- | -------- | -------- | 377| COUNTRY_CODE_FROM_LOCALE | 1 | Country code obtained from the language configuration of the globalization module.| 378| COUNTRY_CODE_FROM_SIM | 2 | Country code obtained from the SIM card.| 379| COUNTRY_CODE_FROM_LOCATION | 3 | Country code obtained using the reverse geocoding function based on the user's location information.| 380| COUNTRY_CODE_FROM_NETWORK | 4 | Country code obtained from the cellular network registration information.| 381 382 383## LocatingRequiredDataType<sup>10+</sup> 384 385Defines the type of the required data of the location service. 386 387**System capability**: SystemCapability.Location.Location.Core 388 389**System API**: This is a system API. 390 391| Name| Value| Description| 392| -------- | -------- | -------- | 393| WIFI | 1 | Wi-Fi scanning information.| 394| BLUETOOTH | 2 | Bluetooth scanning information.| 395 396 397## geoLocationManager.on('locationChange') 398 399on(type: 'locationChange', request: LocationRequest, callback: Callback<Location>): void 400 401Subscribes to location change events with a location request initiated. 402 403**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 404 405**System capability**: SystemCapability.Location.Location.Core 406 407**Parameters** 408 409 | Name| Type| Mandatory| Description| 410 | -------- | -------- | -------- | -------- | 411 | type | string | Yes| Event type. The value **locationChange** indicates a location change.| 412 | request | [LocationRequest](#locationrequest) | Yes| Location request.| 413 | callback | Callback<[Location](#location)> | Yes| Callback used to receive location change events.| 414 415**Error codes** 416 417For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 418 419| ID| Error Message| 420| -------- | ---------------------------------------- | 421|3301000 | Location service is unavailable. | 422|3301100 | The location switch is off. | 423|3301200 | Failed to obtain the geographical location. | 424 425**Example** 426 427 ```ts 428 import geoLocationManager from '@ohos.geoLocationManager'; 429 import BusinessError from "@ohos.base"; 430 let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0}; 431 let locationChange = (location:geoLocationManager.Location):void => { 432 console.log('locationChanger: data: ' + JSON.stringify(location)); 433 }; 434 try { 435 geoLocationManager.on('locationChange', requestInfo, locationChange); 436 } catch (err) { 437 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 438 } 439 440 ``` 441 442 443## geoLocationManager.off('locationChange') 444 445off(type: 'locationChange', callback?: Callback<Location>): void 446 447Unsubscribes from location change events with the corresponding location request deleted. 448 449**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 450 451**System capability**: SystemCapability.Location.Location.Core 452 453**Parameters** 454 455 | Name| Type| Mandatory| Description| 456 | -------- | -------- | -------- | -------- | 457 | type | string | Yes| Event type. The value **locationChange** indicates a location change.| 458 | callback | Callback<[Location](#location)> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 459 460**Error codes** 461 462For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 463 464| ID| Error Message| 465| -------- | ---------------------------------------- | 466|3301000 | Location service is unavailable. | 467|3301100 | The location switch is off. | 468|3301200 | Failed to obtain the geographical location. | 469 470**Example** 471 472 ```ts 473 import geoLocationManager from '@ohos.geoLocationManager'; 474 import BusinessError from "@ohos.base"; 475 let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0}; 476 let locationChange = (location:geoLocationManager.Location):void => { 477 console.log('locationChanger: data: ' + JSON.stringify(location)); 478 }; 479 try { 480 geoLocationManager.on('locationChange', requestInfo, locationChange); 481 geoLocationManager.off('locationChange', locationChange); 482 } catch (err) { 483 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 484 } 485 ``` 486 487 488## geoLocationManager.on('locationEnabledChange') 489 490on(type: 'locationEnabledChange', callback: Callback<boolean>): void 491 492Subscribes to location service status change events. 493 494**System capability**: SystemCapability.Location.Location.Core 495 496**Parameters** 497 498 | Name| Type| Mandatory| Description| 499 | -------- | -------- | -------- | -------- | 500 | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change.| 501 | callback | Callback<boolean> | Yes| Callback used to receive location service status change events.| 502 503**Error codes** 504 505For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 506 507| ID| Error Message| 508| -------- | ---------------------------------------- | 509|3301000 | Location service is unavailable. | 510 511**Example** 512 513 ```ts 514 import geoLocationManager from '@ohos.geoLocationManager'; 515 import BusinessError from "@ohos.base"; 516 let locationEnabledChange = (state:boolean):void => { 517 console.log('locationEnabledChange: ' + JSON.stringify(state)); 518 } 519 try { 520 geoLocationManager.on('locationEnabledChange', locationEnabledChange); 521 } catch (err) { 522 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 523 } 524 ``` 525 526 527## geoLocationManager.off('locationEnabledChange') 528 529off(type: 'locationEnabledChange', callback?: Callback<boolean>): void; 530 531Unsubscribes from location service status change events. 532 533**System capability**: SystemCapability.Location.Location.Core 534 535**Parameters** 536 537 | Name| Type| Mandatory| Description| 538 | -------- | -------- | -------- | -------- | 539 | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change.| 540 | callback | Callback<boolean> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 541 542**Error codes** 543 544For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 545 546| ID| Error Message| 547| -------- | ---------------------------------------- | 548|3301000 | Location service is unavailable. | 549 550**Example** 551 552 ```ts 553 import geoLocationManager from '@ohos.geoLocationManager'; 554 import BusinessError from "@ohos.base"; 555 let locationEnabledChange = (state:boolean):void => { 556 console.log('locationEnabledChange: state: ' + JSON.stringify(state)); 557 } 558 try { 559 geoLocationManager.on('locationEnabledChange', locationEnabledChange); 560 geoLocationManager.off('locationEnabledChange', locationEnabledChange); 561 } catch (err) { 562 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 563 } 564 ``` 565 566 567## geoLocationManager.on('cachedGnssLocationsChange') 568 569on(type: 'cachedGnssLocationsChange', request: CachedGnssLocationsRequest, callback: Callback<Array<Location>>): void; 570 571Subscribes to cached GNSS location reports. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported. 572 573**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 574 575**System capability**: SystemCapability.Location.Location.Gnss 576 577**Parameters** 578 579 | Name| Type| Mandatory| Description| 580 | -------- | -------- | -------- | -------- | 581 | type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.| 582 | request | [CachedGnssLocationsRequest](#cachedgnsslocationsrequest) | Yes| Request for reporting cached GNSS location.| 583 | callback | Callback<boolean> | Yes| Callback used to receive cached GNSS locations.| 584 585**Error codes** 586 587For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 588 589| ID| Error Message| 590| -------- | ---------------------------------------- | 591|3301000 | Location service is unavailable. | 592|3301100 | The location switch is off. | 593|3301200 | Failed to obtain the geographical location. | 594 595**Example** 596 597 ```ts 598 import geoLocationManager from '@ohos.geoLocationManager'; 599 import BusinessError from "@ohos.base"; 600 let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => { 601 console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations)); 602 } 603 let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; 604 try { 605 geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb); 606 } catch (err) { 607 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 608 } 609 ``` 610 611 612## geoLocationManager.off('cachedGnssLocationsChange') 613 614off(type: 'cachedGnssLocationsChange', callback?: Callback<Array<Location>>): void; 615 616Unsubscribes from cached GNSS location reports. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported. 617 618**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 619 620**System capability**: SystemCapability.Location.Location.Gnss 621 622**Parameters** 623 624 | Name| Type| Mandatory| Description| 625 | -------- | -------- | -------- | -------- | 626 | type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.| 627 | callback | Callback<boolean> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 628 629**Error codes** 630 631For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 632 633| ID| Error Message| 634| -------- | ---------------------------------------- | 635|3301000 | Location service is unavailable. | 636|3301100 | The location switch is off. | 637|3301200 | Failed to obtain the geographical location. | 638 639**Example** 640 641 ```ts 642 import geoLocationManager from '@ohos.geoLocationManager'; 643 import BusinessError from "@ohos.base"; 644 let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => { 645 console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations)); 646 } 647 let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; 648 try { 649 geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb); 650 geoLocationManager.off('cachedGnssLocationsChange'); 651 } catch (err) { 652 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 653 } 654 ``` 655 656 657## geoLocationManager.on('satelliteStatusChange') 658 659on(type: 'satelliteStatusChange', callback: Callback<SatelliteStatusInfo>): void; 660 661Subscribes to GNSS satellite status change events. 662 663**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 664 665**System capability**: SystemCapability.Location.Location.Gnss 666 667**Parameters** 668 669 | Name| Type| Mandatory| Description| 670 | -------- | -------- | -------- | -------- | 671 | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change.| 672 | callback | Callback<[SatelliteStatusInfo](#satellitestatusinfo)> | Yes| Callback used to receive GNSS satellite status change events.| 673 674**Error codes** 675 676For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 677 678| ID| Error Message| 679| -------- | ---------------------------------------- | 680|3301000 | Location service is unavailable. | 681|3301100 | The location switch is off. | 682 683**Example** 684 685 ```ts 686 import geoLocationManager from '@ohos.geoLocationManager'; 687 import BusinessError from "@ohos.base"; 688 let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => { 689 console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo)); 690 } 691 692 try { 693 geoLocationManager.on('satelliteStatusChange', gnssStatusCb); 694 } catch (err) { 695 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 696 } 697 ``` 698 699 700## geoLocationManager.off('satelliteStatusChange') 701 702off(type: 'satelliteStatusChange', callback?: Callback<SatelliteStatusInfo>): void; 703 704Unsubscribes from GNSS satellite status change events. 705 706**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 707 708**System capability**: SystemCapability.Location.Location.Gnss 709 710**Parameters** 711 712 | Name| Type| Mandatory| Description| 713 | -------- | -------- | -------- | -------- | 714 | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change.| 715 | callback | Callback<[SatelliteStatusInfo](#satellitestatusinfo)> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 716 717**Error codes** 718 719For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 720 721| ID| Error Message| 722| -------- | ---------------------------------------- | 723|3301000 | Location service is unavailable. | 724|3301100 | The location switch is off. | 725 726 727**Example** 728 729 ```ts 730 import geoLocationManager from '@ohos.geoLocationManager'; 731 import BusinessError from "@ohos.base"; 732 let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => { 733 console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo)); 734 } 735 try { 736 geoLocationManager.on('satelliteStatusChange', gnssStatusCb); 737 geoLocationManager.off('satelliteStatusChange', gnssStatusCb); 738 } catch (err) { 739 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 740 } 741 ``` 742 743 744## geoLocationManager.on('nmeaMessage') 745 746on(type: 'nmeaMessage', callback: Callback<string>): void; 747 748Subscribes to GNSS NMEA message change events. 749 750**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 751 752**System capability**: SystemCapability.Location.Location.Gnss 753 754**Parameters** 755 756 | Name| Type| Mandatory| Description| 757 | -------- | -------- | -------- | -------- | 758 | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change.| 759 | callback | Callback<string> | Yes| Callback used to receive GNSS NMEA message change events.| 760 761**Error codes** 762 763For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 764 765| ID| Error Message| 766| -------- | ---------------------------------------- | 767|3301000 | Location service is unavailable. | 768|3301100 | The location switch is off. | 769 770 771**Example** 772 773 ```ts 774 import geoLocationManager from '@ohos.geoLocationManager'; 775 import BusinessError from "@ohos.base"; 776 let nmeaCb = (str:string):void => { 777 console.log('nmeaMessage: ' + JSON.stringify(str)); 778 } 779 780 try { 781 geoLocationManager.on('nmeaMessage', nmeaCb ); 782 } catch (err) { 783 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 784 } 785 ``` 786 787 788## geoLocationManager.off('nmeaMessage') 789 790off(type: 'nmeaMessage', callback?: Callback<string>): void; 791 792Unsubscribes from GNSS NMEA message change events. 793 794**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 795 796**System capability**: SystemCapability.Location.Location.Gnss 797 798**Parameters** 799 800 | Name| Type| Mandatory| Description| 801 | -------- | -------- | -------- | -------- | 802 | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change.| 803 | callback | Callback<string> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 804 805**Error codes** 806 807For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 808 809| ID| Error Message| 810| -------- | ---------------------------------------- | 811|3301000 | Location service is unavailable. | 812|3301100 | The location switch is off. | 813 814 815**Example** 816 817 ```ts 818 import geoLocationManager from '@ohos.geoLocationManager'; 819 import BusinessError from "@ohos.base"; 820 let nmeaCb = (str:string):void => { 821 console.log('nmeaMessage: ' + JSON.stringify(str)); 822 } 823 824 try { 825 geoLocationManager.on('nmeaMessage', nmeaCb); 826 geoLocationManager.off('nmeaMessage', nmeaCb); 827 } catch (err) { 828 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 829 } 830 ``` 831 832 833## geoLocationManager.on('gnssFenceStatusChange') 834 835on(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void; 836 837Subscribes to status change events of the specified geofence. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported. 838 839**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 840 841**System capability**: SystemCapability.Location.Location.Geofence 842 843**Parameters** 844 845 | Name| Type| Mandatory| Description| 846 | -------- | -------- | -------- | -------- | 847 | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.| 848 | request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.| 849 | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.| 850 851**Error codes** 852 853For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 854 855| ID| Error Message| 856| -------- | ---------------------------------------- | 857|3301000 | Location service is unavailable. | 858|3301100 | The location switch is off. | 859|3301600 | Failed to operate the geofence. | 860 861**Example** 862 863 ```ts 864 import geoLocationManager from '@ohos.geoLocationManager'; 865 import wantAgent from '@ohos.app.ability.wantAgent'; 866 import BusinessError from "@ohos.base"; 867 868 let wantAgentInfo:wantAgent.WantAgentInfo = { 869 wants: [ 870 { 871 bundleName: "com.example.myapplication", 872 abilityName: "EntryAbility", 873 action: "action1" 874 } 875 ], 876 operationType: wantAgent.OperationType.START_ABILITY, 877 requestCode: 0, 878 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 879 }; 880 881 wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { 882 let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}}; 883 try { 884 geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj); 885 } catch (err) { 886 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 887 } 888 }); 889 ``` 890 891 892## geoLocationManager.off('gnssFenceStatusChange') 893 894off(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void; 895 896Unsubscribes from status change events of the specified geofence. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported. 897 898**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 899 900**System capability**: SystemCapability.Location.Location.Geofence 901 902**Parameters** 903 904 | Name| Type| Mandatory| Description| 905 | -------- | -------- | -------- | -------- | 906 | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.| 907 | request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.| 908 | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.| 909 910**Error codes** 911 912For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 913 914| ID| Error Message| 915| -------- | ---------------------------------------- | 916|3301000 | Location service is unavailable. | 917|3301100 | The location switch is off. | 918|3301600 | Failed to operate the geofence. | 919 920**Example** 921 922 ```ts 923 import geoLocationManager from '@ohos.geoLocationManager'; 924 import wantAgent from '@ohos.app.ability.wantAgent'; 925 import BusinessError from "@ohos.base"; 926 927 let wantAgentInfo:wantAgent.WantAgentInfo = { 928 wants: [ 929 { 930 bundleName: "com.example.myapplication", 931 abilityName: "EntryAbility", 932 action: "action1", 933 } 934 ], 935 operationType: wantAgent.OperationType.START_ABILITY, 936 requestCode: 0, 937 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 938 }; 939 940 wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { 941 let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};; 942 try { 943 geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj); 944 geoLocationManager.off('gnssFenceStatusChange', requestInfo, wantAgentObj); 945 } catch (err) { 946 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 947 } 948 }); 949 ``` 950 951 952## geoLocationManager.on('countryCodeChange') 953 954on(type: 'countryCodeChange', callback: Callback<CountryCode>): void; 955 956Subscribes to country code change events. 957 958**System capability**: SystemCapability.Location.Location.Core 959 960**Parameters** 961 962 | Name| Type| Mandatory| Description| 963 | -------- | -------- | -------- | -------- | 964 | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change.| 965 | callback | Callback<[CountryCode](#countrycode)> | Yes| Callback used to receive country code change events.| 966 967**Error codes** 968 969For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 970 971| ID| Error Message| 972| -------- | ---------------------------------------- | 973|3301000 | Location service is unavailable. | 974|3301500 | Failed to query the area information. | 975 976 977**Example** 978 979 ```ts 980 import geoLocationManager from '@ohos.geoLocationManager'; 981 import BusinessError from "@ohos.base"; 982 let callback = (code:geoLocationManager.CountryCode):void => { 983 console.log('countryCodeChange: ' + JSON.stringify(code)); 984 } 985 986 try { 987 geoLocationManager.on('countryCodeChange', callback); 988 } catch (err) { 989 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 990 } 991 ``` 992 993 994## geoLocationManager.off('countryCodeChange') 995 996off(type: 'countryCodeChange', callback?: Callback<CountryCode>): void; 997 998Unsubscribes from country code change events. 999 1000**System capability**: SystemCapability.Location.Location.Core 1001 1002**Parameters** 1003 1004 | Name| Type| Mandatory| Description| 1005 | -------- | -------- | -------- | -------- | 1006 | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change.| 1007 | callback | Callback<[CountryCode](#countrycode)> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 1008 1009**Error codes** 1010 1011For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1012 1013| ID| Error Message| 1014| -------- | ---------------------------------------- | 1015|3301000 | Location service is unavailable. | 1016|3301500 | Failed to query the area information. | 1017 1018**Example** 1019 1020 ```ts 1021 import geoLocationManager from '@ohos.geoLocationManager'; 1022 import BusinessError from "@ohos.base"; 1023 let callback = (code:geoLocationManager.CountryCode):void => { 1024 console.log('countryCodeChange: ' + JSON.stringify(code)); 1025 } 1026 1027 try { 1028 geoLocationManager.on('countryCodeChange', callback); 1029 geoLocationManager.off('countryCodeChange', callback); 1030 } catch (err) { 1031 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1032 } 1033 ``` 1034 1035 1036## geoLocationManager.on('locatingRequiredDataChange')<sup>10+</sup> 1037 1038on(type: 'locatingRequiredDataChange', config: LocatingRequiredDataConfig, callback: Callback<Array<LocatingRequiredData>>): void; 1039 1040Subscribes 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. 1041 1042**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 1043 1044**System capability**: SystemCapability.Location.Location.Core 1045 1046**System API**: This is a system API. 1047 1048**Parameters** 1049 1050 | Name| Type| Mandatory| Description| 1051 | -------- | -------- | -------- | -------- | 1052 | type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.| 1053 | config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.| 1054 | callback | Callback<Array<[LocatingRequiredData](#locatingrequireddata10)>> | Yes| Callback used to receive the required data of the location service.| 1055 1056**Error codes** 1057 1058For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1059 1060| ID| Error Message| 1061| -------- | ---------------------------------------- | 1062|3301800 | Failed to start WiFi or Bluetooth scanning. | 1063 1064**Example** 1065 1066 ```ts 1067 import geoLocationManager from '@ohos.geoLocationManager'; 1068 import BusinessError from "@ohos.base"; 1069 let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => { 1070 console.log('locatingRequiredDataChange: ' + JSON.stringify(code)); 1071 } 1072 let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; 1073 try { 1074 geoLocationManager.on('locatingRequiredDataChange', config, callback); 1075 } catch (err) { 1076 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1077 } 1078 ``` 1079 1080 1081## geoLocationManager.off('locatingRequiredDataChange')<sup>10+</sup> 1082 1083off(type: 'locatingRequiredDataChange', callback?: Callback<Array<LocatingRequiredData>>): void; 1084 1085Unsubscribes from changes in the required data of the location service and stops Wi-Fi and Bluetooth scanning. 1086 1087**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 1088 1089**System capability**: SystemCapability.Location.Location.Core 1090 1091**System API**: This is a system API. 1092 1093**Parameters** 1094 1095 | Name| Type| Mandatory| Description| 1096 | -------- | -------- | -------- | -------- | 1097 | type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.| 1098 | callback | Callback<Array<[LocatingRequiredData](#locatingrequireddata10)>> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 1099 1100**Error codes** 1101 1102For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1103 1104**Example** 1105 1106 ```ts 1107 import geoLocationManager from '@ohos.geoLocationManager'; 1108 import BusinessError from "@ohos.base"; 1109 let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => { 1110 console.log('locatingRequiredDataChange: ' + JSON.stringify(code)); 1111 } 1112 let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; 1113 try { 1114 geoLocationManager.on('locatingRequiredDataChange', config, callback); 1115 geoLocationManager.off('locatingRequiredDataChange', callback); 1116 } catch (err) { 1117 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1118 } 1119 ``` 1120 1121 1122## geoLocationManager.getCurrentLocation 1123 1124getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback<Location>): void 1125 1126Obtains the current location. This API uses an asynchronous callback to return the result. 1127 1128**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1129 1130**System capability**: SystemCapability.Location.Location.Core 1131 1132**Parameters** 1133 1134 | Name| Type| Mandatory| Description| 1135 | -------- | -------- | -------- | -------- | 1136 | request | [CurrentLocationRequest](#currentlocationrequest) | Yes| Location request.| 1137 | callback | AsyncCallback<[Location](#location)> | Yes| Callback used to receive the current location.| 1138 1139**Error codes** 1140 1141For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1142 1143| ID| Error Message| 1144| -------- | ---------------------------------------- | 1145|3301000 | Location service is unavailable. | 1146|3301100 | The location switch is off. | 1147|3301200 | Failed to obtain the geographical location. | 1148 1149**Example** 1150 1151 ```ts 1152 import geoLocationManager from '@ohos.geoLocationManager'; 1153 import BusinessError from "@ohos.base"; 1154 let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0}; 1155 let locationChange = (err:BusinessError.BusinessError, location:geoLocationManager.Location):void => { 1156 if (err) { 1157 console.log('locationChanger: err=' + JSON.stringify(err)); 1158 } 1159 if (location) { 1160 console.log('locationChanger: location=' + JSON.stringify(location)); 1161 } 1162 }; 1163 1164 try { 1165 geoLocationManager.getCurrentLocation(requestInfo, locationChange); 1166 } catch (err) { 1167 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1168 } 1169 ``` 1170 1171## geoLocationManager.getCurrentLocation 1172 1173getCurrentLocation(callback: AsyncCallback<Location>): void; 1174 1175Obtains the current location. This API uses an asynchronous callback to return the result. 1176 1177**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1178 1179**System capability**: SystemCapability.Location.Location.Core 1180 1181**Parameters** 1182 1183 | Name| Type| Mandatory| Description| 1184 | -------- | -------- | -------- | -------- | 1185 | callback | AsyncCallback<[Location](#location)> | Yes| Callback used to receive the current location.| 1186 1187**Error codes** 1188 1189For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1190 1191| ID| Error Message| 1192| -------- | ---------------------------------------- | 1193|3301000 | Location service is unavailable. | 1194|3301100 | The location switch is off. | 1195|3301200 | Failed to obtain the geographical location. | 1196 1197**Example** 1198 1199 ```ts 1200 import geoLocationManager from '@ohos.geoLocationManager'; 1201 import BusinessError from "@ohos.base"; 1202 let locationChange = (err:BusinessError.BusinessError, location:geoLocationManager.Location) => { 1203 if (err) { 1204 console.log('locationChanger: err=' + JSON.stringify(err)); 1205 } 1206 if (location) { 1207 console.log('locationChanger: location=' + JSON.stringify(location)); 1208 } 1209 }; 1210 1211 try { 1212 geoLocationManager.getCurrentLocation(locationChange); 1213 } catch (err) { 1214 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1215 } 1216 ``` 1217 1218## geoLocationManager.getCurrentLocation 1219 1220getCurrentLocation(request?: CurrentLocationRequest): Promise<Location> 1221 1222Obtains the current location. This API uses a promise to return the result. 1223 1224**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1225 1226**System capability**: SystemCapability.Location.Location.Core 1227 1228**Parameters** 1229 1230 | Name| Type| Mandatory| Description| 1231 | -------- | -------- | -------- | -------- | 1232 | request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.| 1233 1234**Return value** 1235 1236 | Name| Type| Mandatory| Description| 1237 | -------- | -------- | -------- | -------- | 1238 | Promise<[Location](#location)> | [Location](#location) | NA | Promise used to return the current location.| 1239 1240**Error codes** 1241 1242For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1243 1244| ID| Error Message| 1245| -------- | ---------------------------------------- | 1246|3301000 | Location service is unavailable. | 1247|3301100 | The location switch is off. | 1248|3301200 | Failed to obtain the geographical location. | 1249 1250**Example** 1251 1252 ```ts 1253 import geoLocationManager from '@ohos.geoLocationManager'; 1254 import BusinessError from "@ohos.base"; 1255 let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0}; 1256 try { 1257 geoLocationManager.getCurrentLocation(requestInfo).then((result) => { 1258 console.log('current location: ' + JSON.stringify(result)); 1259 }) 1260 .catch((error:number) => { 1261 console.log('promise, getCurrentLocation: error=' + JSON.stringify(error)); 1262 }); 1263 } catch (err) { 1264 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1265 } 1266 ``` 1267 1268 1269## geoLocationManager.getLastLocation 1270 1271getLastLocation(): Location 1272 1273Obtains the last location. 1274 1275**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1276 1277**System capability**: SystemCapability.Location.Location.Core 1278 1279**Return value** 1280 1281 | Name| Type| Mandatory| Description| 1282 | -------- | -------- | -------- | -------- | 1283 | Location | [Location](#location) | NA | Location information.| 1284 1285**Error codes** 1286 1287For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1288 1289| ID| Error Message| 1290| -------- | ---------------------------------------- | 1291|3301000 | Location service is unavailable. | 1292|3301100 | The location switch is off. | 1293|3301200 |Failed to obtain the geographical location. | 1294 1295**Example** 1296 1297 ```ts 1298 import geoLocationManager from '@ohos.geoLocationManager'; 1299 import BusinessError from "@ohos.base"; 1300 try { 1301 let location = geoLocationManager.getLastLocation(); 1302 } catch (err) { 1303 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1304 } 1305 ``` 1306 1307 1308## geoLocationManager.isLocationEnabled 1309 1310isLocationEnabled(): boolean 1311 1312Checks whether the location service is enabled. 1313 1314**System capability**: SystemCapability.Location.Location.Core 1315 1316**Return value** 1317 1318 | Name| Type| Mandatory| Description| 1319 | -------- | -------- | -------- | -------- | 1320 | boolean | boolean | NA | Result indicating whether the location service is enabled.| 1321 1322**Error codes** 1323 1324For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1325 1326| ID| Error Message| 1327| -------- | ---------------------------------------- | 1328|3301000 | Location service is unavailable. | 1329 1330**Example** 1331 1332 ```ts 1333 import geoLocationManager from '@ohos.geoLocationManager'; 1334 import BusinessError from "@ohos.base"; 1335 try { 1336 let locationEnabled = geoLocationManager.isLocationEnabled(); 1337 } catch (err) { 1338 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1339 } 1340 ``` 1341 1342 1343## geoLocationManager.enableLocation 1344 1345enableLocation(callback: AsyncCallback<void>): void; 1346 1347Enables the location service. This API uses an asynchronous callback to return the result. 1348 1349**System API**: This is a system API. 1350 1351**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS 1352 1353**System capability**: SystemCapability.Location.Location.Core 1354 1355**Parameters** 1356 1357 | Name| Type| Mandatory| Description| 1358 | -------- | -------- | -------- | -------- | 1359 | callback | AsyncCallback<void> | Yes| Callback used to receive the error message.| 1360 1361**Error codes** 1362 1363For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1364 1365| ID| Error Message| 1366| -------- | ---------------------------------------- | 1367|3301000 | Location service is unavailable. | 1368 1369**Example** 1370 1371 ```ts 1372 import geoLocationManager from '@ohos.geoLocationManager'; 1373 import BusinessError from "@ohos.base"; 1374 try { 1375 geoLocationManager.enableLocation((err, data) => { 1376 if (err) { 1377 console.log('enableLocation: err=' + JSON.stringify(err)); 1378 } 1379 }); 1380 } catch (err) { 1381 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1382 } 1383 ``` 1384 1385 1386## geoLocationManager.enableLocation 1387 1388enableLocation(): Promise<void> 1389 1390Enables the location service. This API uses a promise to return the result. 1391 1392**System API**: This is a system API. 1393 1394**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS 1395 1396**System capability**: SystemCapability.Location.Location.Core 1397 1398**Return value** 1399 1400 | Name| Type| Mandatory| Description| 1401 | -------- | -------- | -------- | -------- | 1402 | Promise<void> | void | NA | Promise used to return the error message.| 1403 1404**Error codes** 1405 1406For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1407 1408| ID| Error Message| 1409| -------- | ---------------------------------------- | 1410|3301000 | Location service is unavailable. | 1411 1412**Example** 1413 1414 ```ts 1415 import geoLocationManager from '@ohos.geoLocationManager'; 1416 import BusinessError from "@ohos.base"; 1417 try { 1418 geoLocationManager.enableLocation().then((result) => { 1419 console.log('promise, enableLocation succeed'); 1420 }) 1421 .catch((error:number) => { 1422 console.log('promise, enableLocation: error=' + JSON.stringify(error)); 1423 }); 1424 } catch (err) { 1425 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1426 } 1427 ``` 1428 1429## geoLocationManager.disableLocation 1430 1431disableLocation(): void; 1432 1433Disables the location service. 1434 1435**System API**: This is a system API. 1436 1437**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS 1438 1439**System capability**: SystemCapability.Location.Location.Core 1440 1441**Error codes** 1442 1443For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1444 1445| ID| Error Message| 1446| -------- | ---------------------------------------- | 1447|3301000 | Location service is unavailable. | 1448 1449**Example** 1450 1451 ```ts 1452 import geoLocationManager from '@ohos.geoLocationManager'; 1453 import BusinessError from "@ohos.base"; 1454 try { 1455 geoLocationManager.disableLocation(); 1456 } catch (err) { 1457 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1458 } 1459 ``` 1460 1461 1462## geoLocationManager.getAddressesFromLocation 1463 1464getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void 1465 1466Converts coordinates into geographic description through reverse geocoding. This API uses an asynchronous callback to return the result. 1467 1468**System capability**: SystemCapability.Location.Location.Geocoder 1469 1470**Parameters** 1471 1472 | Name| Type| Mandatory| Description| 1473 | -------- | -------- | -------- | -------- | 1474 | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.| 1475 | callback | AsyncCallback<Array<[GeoAddress](#geoaddress)>> | Yes| Callback used to receive the reverse geocoding result.| 1476 1477**Error codes** 1478 1479For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1480 1481| ID| Error Message| 1482| -------- | ---------------------------------------- | 1483|3301000 | Location service is unavailable. | 1484|3301300 | Reverse geocoding query failed. | 1485 1486**Example** 1487 1488 ```ts 1489 import geoLocationManager from '@ohos.geoLocationManager'; 1490 import BusinessError from "@ohos.base"; 1491 let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; 1492 try { 1493 geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { 1494 if (err) { 1495 console.log('getAddressesFromLocation: err=' + JSON.stringify(err)); 1496 } 1497 if (data) { 1498 console.log('getAddressesFromLocation: data=' + JSON.stringify(data)); 1499 } 1500 }); 1501 } catch (err) { 1502 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1503 } 1504 ``` 1505 1506 1507## geoLocationManager.getAddressesFromLocation 1508 1509getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise<Array<GeoAddress>>; 1510 1511Converts coordinates into geographic description through reverse geocoding. This API uses a promise to return the result. 1512 1513**System capability**: SystemCapability.Location.Location.Geocoder 1514 1515**Parameters** 1516 1517 | Name| Type| Mandatory| Description| 1518 | -------- | -------- | -------- | -------- | 1519 | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.| 1520 1521**Return value** 1522 1523 | Name| Type| Mandatory| Description| 1524 | -------- | -------- | -------- | -------- | 1525 | Promise<Array<[GeoAddress](#geoaddress)>> | Array<[GeoAddress](#geoaddress)> | NA | Promise used to return the reverse geocoding result.| 1526 1527**Error codes** 1528 1529For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1530 1531| ID| Error Message| 1532| -------- | ---------------------------------------- | 1533|3301000 | Location service is unavailable. | 1534|3301300 | Reverse geocoding query failed. | 1535 1536**Example** 1537 1538 ```ts 1539 import geoLocationManager from '@ohos.geoLocationManager'; 1540 import BusinessError from "@ohos.base"; 1541 let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; 1542 try { 1543 geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { 1544 console.log('getAddressesFromLocation: ' + JSON.stringify(data)); 1545 }) 1546 .catch((error:number) => { 1547 console.log('promise, getAddressesFromLocation: error=' + JSON.stringify(error)); 1548 }); 1549 } catch (err) { 1550 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1551 } 1552 ``` 1553 1554 1555## geoLocationManager.getAddressesFromLocationName 1556 1557getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void 1558 1559Converts geographic description into coordinates through geocoding. This API uses an asynchronous callback to return the result. 1560 1561**System capability**: SystemCapability.Location.Location.Geocoder 1562 1563**Parameters** 1564 1565 | Name| Type| Mandatory| Description| 1566 | -------- | -------- | -------- | -------- | 1567 | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.| 1568 | callback | AsyncCallback<Array<[GeoAddress](#geoaddress)>> | Yes| Callback used to receive the geocoding result.| 1569 1570**Error codes** 1571 1572For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1573 1574| ID| Error Message| 1575| -------- | ---------------------------------------- | 1576|3301000 | Location service is unavailable. | 1577|3301400 | Geocoding query failed. | 1578 1579**Example** 1580 1581 ```ts 1582 import geoLocationManager from '@ohos.geoLocationManager'; 1583 import BusinessError from "@ohos.base"; 1584 let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; 1585 try { 1586 geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => { 1587 if (err) { 1588 console.log('getAddressesFromLocationName: err=' + JSON.stringify(err)); 1589 } 1590 if (data) { 1591 console.log('getAddressesFromLocationName: data=' + JSON.stringify(data)); 1592 } 1593 }); 1594 } catch (err) { 1595 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1596 } 1597 ``` 1598 1599 1600## geoLocationManager.getAddressesFromLocationName 1601 1602getAddressesFromLocationName(request: GeoCodeRequest): Promise<Array<GeoAddress>> 1603 1604Converts geographic description into coordinates through geocoding. This API uses a promise to return the result. 1605 1606**System capability**: SystemCapability.Location.Location.Geocoder 1607 1608**Parameters** 1609 1610 | Name| Type| Mandatory| Description| 1611 | -------- | -------- | -------- | -------- | 1612 | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.| 1613 1614**Return value** 1615 1616 | Name| Type| Mandatory| Description| 1617 | -------- | -------- | -------- | -------- | 1618 | Promise<Array<[GeoAddress](#geoaddress)>> | Array<[GeoAddress](#geoaddress)> | NA | Promise used to return the geocoding result.| 1619 1620**Error codes** 1621 1622For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1623 1624| ID| Error Message| 1625| -------- | ---------------------------------------- | 1626|3301000 | Location service is unavailable. | 1627|3301400 | Geocoding query failed. | 1628 1629**Example** 1630 1631 ```ts 1632 import geoLocationManager from '@ohos.geoLocationManager'; 1633 import BusinessError from "@ohos.base"; 1634 let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; 1635 try { 1636 geoLocationManager.getAddressesFromLocationName(geocodeRequest).then((result) => { 1637 console.log('getAddressesFromLocationName: ' + JSON.stringify(result)); 1638 }) 1639 .catch((error:number) => { 1640 console.log('promise, getAddressesFromLocationName: error=' + JSON.stringify(error)); 1641 }); 1642 } catch (err) { 1643 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1644 } 1645 ``` 1646 1647## geoLocationManager.isGeocoderAvailable 1648 1649isGeocoderAvailable(): boolean; 1650 1651Obtains the (reverse) geocoding service status. 1652 1653**System capability**: SystemCapability.Location.Location.Geocoder 1654 1655**Return value** 1656 1657 | Name| Type| Mandatory| Description| 1658 | -------- | -------- | -------- | -------- | 1659 | boolean | boolean | NA | Result indicating whether the (reverse) geocoding service is available.| 1660 1661**Error codes** 1662 1663For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1664 1665| ID| Error Message| 1666| -------- | ---------------------------------------- | 1667|3301000 | Location service is unavailable. | 1668 1669**Example** 1670 1671 ```ts 1672 import geoLocationManager from '@ohos.geoLocationManager'; 1673 import BusinessError from "@ohos.base"; 1674 try { 1675 let isAvailable = geoLocationManager.isGeocoderAvailable(); 1676 } catch (err) { 1677 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1678 } 1679 ``` 1680 1681 1682## geoLocationManager.getCachedGnssLocationsSize 1683 1684getCachedGnssLocationsSize(callback: AsyncCallback<number>): void; 1685 1686Obtains the number of cached GNSS locations. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported. 1687 1688**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1689 1690**System capability**: SystemCapability.Location.Location.Gnss 1691 1692**Parameters** 1693 1694 | Name| Type| Mandatory| Description| 1695 | -------- | -------- | -------- | -------- | 1696 | callback | AsyncCallback<number> | Yes| Callback used to receive the number of cached GNSS locations. | 1697 1698**Error codes** 1699 1700For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1701 1702| ID| Error Message| 1703| -------- | ---------------------------------------- | 1704|3301000 | Location service is unavailable. | 1705|3301100 | The location switch is off. | 1706 1707**Example** 1708 1709 ```ts 1710 import geoLocationManager from '@ohos.geoLocationManager'; 1711 import BusinessError from "@ohos.base"; 1712 try { 1713 geoLocationManager.getCachedGnssLocationsSize((err, size) => { 1714 if (err) { 1715 console.log('getCachedGnssLocationsSize: err=' + JSON.stringify(err)); 1716 } 1717 if (size) { 1718 console.log('getCachedGnssLocationsSize: size=' + JSON.stringify(size)); 1719 } 1720 }); 1721 } catch (err) { 1722 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1723 } 1724 ``` 1725 1726 1727## geoLocationManager.getCachedGnssLocationsSize 1728 1729getCachedGnssLocationsSize(): Promise<number>; 1730 1731Obtains the number of cached GNSS locations. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported. 1732 1733**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1734 1735**System capability**: SystemCapability.Location.Location.Gnss 1736 1737**Return value** 1738 1739 | Name| Type| Mandatory| Description| 1740 | -------- | -------- | -------- | -------- | 1741 | Promise<number> | number | NA | Promise used to return the number of cached GNSS locations.| 1742 1743**Error codes** 1744 1745For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1746 1747| ID| Error Message| 1748| -------- | ---------------------------------------- | 1749|3301000 | Location service is unavailable. | 1750|3301100 | The location switch is off. | 1751 1752**Example** 1753 1754 ```ts 1755 import geoLocationManager from '@ohos.geoLocationManager'; 1756 import BusinessError from "@ohos.base"; 1757 try { 1758 geoLocationManager.getCachedGnssLocationsSize().then((result) => { 1759 console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result)); 1760 }) 1761 .catch((error:number) => { 1762 console.log('promise, getCachedGnssLocationsSize: error=' + JSON.stringify(error)); 1763 }); 1764 } catch (err) { 1765 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1766 } 1767 ``` 1768 1769 1770## geoLocationManager.flushCachedGnssLocations 1771 1772flushCachedGnssLocations(callback: AsyncCallback<void>): void; 1773 1774Obtains all cached GNSS locations and clears the GNSS cache queue. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported. 1775 1776**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1777 1778**System capability**: SystemCapability.Location.Location.Gnss 1779 1780**Parameters** 1781 1782 | Name| Type| Mandatory| Description| 1783 | -------- | -------- | -------- | -------- | 1784 | callback | AsyncCallback<void> | Yes| Callback used to receive the error message.| 1785 1786**Error codes** 1787 1788For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1789 1790| ID| Error Message| 1791| -------- | ---------------------------------------- | 1792|3301000 | Location service is unavailable. | 1793|3301100 | The location switch is off. | 1794|3301200 | Failed to obtain the geographical location. | 1795 1796**Example** 1797 1798 ```ts 1799 import geoLocationManager from '@ohos.geoLocationManager'; 1800 import BusinessError from "@ohos.base"; 1801 try { 1802 geoLocationManager.flushCachedGnssLocations((err, result) => { 1803 if (err) { 1804 console.log('flushCachedGnssLocations: err=' + JSON.stringify(err)); 1805 } 1806 }); 1807 } catch (err) { 1808 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1809 } 1810 ``` 1811 1812 1813## geoLocationManager.flushCachedGnssLocations 1814 1815flushCachedGnssLocations(): Promise<void>; 1816 1817Obtains all cached GNSS locations and clears the GNSS cache queue. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported. 1818 1819**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1820 1821**System capability**: SystemCapability.Location.Location.Gnss 1822 1823**Return value** 1824 1825 | Name| Type| Mandatory| Description| 1826 | -------- | -------- | -------- | -------- | 1827 | Promise<void> | void | NA | Promise used to receive the error code.| 1828 1829**Error codes** 1830 1831For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1832 1833| ID| Error Message| 1834| -------- | ---------------------------------------- | 1835|3301000 | Location service is unavailable. | 1836|3301100 | The location switch is off. | 1837|3301200 | Failed to obtain the geographical location. | 1838 1839**Example** 1840 1841 ```ts 1842 import geoLocationManager from '@ohos.geoLocationManager'; 1843 import BusinessError from "@ohos.base"; 1844 try { 1845 geoLocationManager.flushCachedGnssLocations().then((result) => { 1846 console.log('promise, flushCachedGnssLocations success'); 1847 }) 1848 .catch((error:number) => { 1849 console.log('promise, flushCachedGnssLocations: error=' + JSON.stringify(error)); 1850 }); 1851 } catch (err) { 1852 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1853 } 1854 ``` 1855 1856 1857## geoLocationManager.sendCommand 1858 1859sendCommand(command: LocationCommand, callback: AsyncCallback<void>): void; 1860 1861Sends an extended command to the location subsystem. 1862 1863**System capability**: SystemCapability.Location.Location.Core 1864 1865**Parameters** 1866 1867 | Name| Type| Mandatory| Description| 1868 | -------- | -------- | -------- | -------- | 1869 | command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.| 1870 | callback | AsyncCallback<void> | Yes| Callback used to receive the error code.| 1871 1872**Error codes** 1873 1874For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1875 1876| ID| Error Message| 1877| -------- | ---------------------------------------- | 1878|3301000 | Location service is unavailable. | 1879 1880**Example** 1881 1882 ```ts 1883 import geoLocationManager from '@ohos.geoLocationManager'; 1884 import BusinessError from "@ohos.base"; 1885 let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"}; 1886 try { 1887 geoLocationManager.sendCommand(requestInfo, (err, result) => { 1888 if (err) { 1889 console.log('sendCommand: err=' + JSON.stringify(err)); 1890 } 1891 }); 1892 } catch (err) { 1893 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1894 } 1895 ``` 1896 1897 1898## geoLocationManager.sendCommand 1899 1900sendCommand(command: LocationCommand): Promise<void>; 1901 1902Sends an extended command to the location subsystem. 1903 1904**System capability**: SystemCapability.Location.Location.Core 1905 1906**Parameters** 1907 1908 | Name| Type| Mandatory| Description| 1909 | -------- | -------- | -------- | -------- | 1910 | command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.| 1911 1912**Return value** 1913 1914 | Name| Type| Mandatory| Description| 1915 | -------- | -------- | -------- | -------- | 1916 | Promise<void> | void | NA | Promise used to receive the error code.| 1917 1918**Error codes** 1919 1920For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1921 1922| ID| Error Message| 1923| -------- | ---------------------------------------- | 1924|3301000 | Location service is unavailable. | 1925 1926**Example** 1927 1928 ```ts 1929 import geoLocationManager from '@ohos.geoLocationManager'; 1930 import BusinessError from "@ohos.base"; 1931 let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"}; 1932 try { 1933 geoLocationManager.sendCommand(requestInfo).then((result) => { 1934 console.log('promise, sendCommand success'); 1935 }) 1936 .catch((error:number) => { 1937 console.log('promise, sendCommand: error=' + JSON.stringify(error)); 1938 }); 1939 } catch (err) { 1940 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1941 } 1942 ``` 1943 1944 1945## geoLocationManager.getCountryCode 1946 1947getCountryCode(callback: AsyncCallback<CountryCode>): void; 1948 1949Obtains the current country code. 1950 1951**System capability**: SystemCapability.Location.Location.Core 1952 1953**Parameters** 1954 1955 | Name| Type| Mandatory| Description| 1956 | -------- | -------- | -------- | -------- | 1957 | callback | AsyncCallback<[CountryCode](#countrycode)> | Yes| Callback used to receive the country code.| 1958 1959**Error codes** 1960 1961For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 1962 1963| ID| Error Message| 1964| -------- | ---------------------------------------- | 1965|3301000 | Location service is unavailable. | 1966|3301500 | Failed to query the area information.| 1967 1968**Example** 1969 1970 ```ts 1971 import geoLocationManager from '@ohos.geoLocationManager'; 1972 import BusinessError from "@ohos.base"; 1973 try { 1974 geoLocationManager.getCountryCode((err, result) => { 1975 if (err) { 1976 console.log('getCountryCode: err=' + JSON.stringify(err)); 1977 } 1978 if (result) { 1979 console.log('getCountryCode: result=' + JSON.stringify(result)); 1980 } 1981 }); 1982 } catch (err) { 1983 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 1984 } 1985 ``` 1986 1987 1988## geoLocationManager.getCountryCode 1989 1990getCountryCode(): Promise<CountryCode>; 1991 1992Obtains the current country code. 1993 1994**System capability**: SystemCapability.Location.Location.Core 1995 1996**Return value** 1997 1998 | Name| Type| Mandatory| Description| 1999 | -------- | -------- | -------- | -------- | 2000 | Promise<[CountryCode](#countrycode)> | [CountryCode](#countrycode) | NA | Promise used to receive the country code.| 2001 2002**Error codes** 2003 2004For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 2005 2006| ID| Error Message| 2007| -------- | ---------------------------------------- | 2008|3301000 | Location service is unavailable. | 2009|3301500 | Failed to query the area information.| 2010 2011**Example** 2012 2013 ```ts 2014 import geoLocationManager from '@ohos.geoLocationManager'; 2015 import BusinessError from "@ohos.base"; 2016 try { 2017 geoLocationManager.getCountryCode() 2018 .then((result) => { 2019 console.log('promise, getCountryCode: result=' + JSON.stringify(result)); 2020 }) 2021 .catch((error:number) => { 2022 console.log('promise, getCountryCode: error=' + JSON.stringify(error)); 2023 }); 2024 } catch (err) { 2025 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 2026 } 2027 ``` 2028 2029 2030## geoLocationManager.enableLocationMock 2031 2032enableLocationMock(): void; 2033 2034Enables the mock location function. 2035 2036**System capability**: SystemCapability.Location.Location.Core 2037 2038**System API**: This is a system API. 2039 2040**Error codes** 2041 2042For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 2043 2044| ID| Error Message| 2045| -------- | ---------------------------------------- | 2046|3301000 | Location service is unavailable. | 2047|3301100 | The location switch is off.| 2048 2049**Example** 2050 2051 ```ts 2052 import geoLocationManager from '@ohos.geoLocationManager'; 2053 import BusinessError from "@ohos.base"; 2054 try { 2055 geoLocationManager.enableLocationMock(); 2056 } catch (err) { 2057 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 2058 } 2059 ``` 2060 2061 2062## geoLocationManager.disableLocationMock 2063 2064disableLocationMock(): void; 2065 2066Disables the mock location function. 2067 2068**System capability**: SystemCapability.Location.Location.Core 2069 2070**System API**: This is a system API. 2071 2072**Error codes** 2073 2074For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 2075 2076| ID| Error Message| 2077| -------- | ---------------------------------------- | 2078|3301000 | Location service is unavailable. | 2079|3301100 | The location switch is off.| 2080 2081**Example** 2082 2083 ```ts 2084 import geoLocationManager from '@ohos.geoLocationManager'; 2085 import BusinessError from "@ohos.base"; 2086 try { 2087 geoLocationManager.disableLocationMock(); 2088 } catch (err) { 2089 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 2090 } 2091 ``` 2092 2093 2094## geoLocationManager.setMockedLocations 2095 2096setMockedLocations(config: LocationMockConfig): void; 2097 2098Sets the mock location information. The mock locations will be reported at the interval specified in this API. 2099 2100This API can be invoked only after [geoLocationManager.enableLocationMock](#geolocationmanagerenablelocationmock) is called. 2101 2102**System capability**: SystemCapability.Location.Location.Core 2103 2104**System API**: This is a system API. 2105 2106**Parameters** 2107 2108 | Name| Type| Mandatory| Description| 2109 | -------- | -------- | -------- | -------- | 2110 | config | [LocationMockConfig](#locationmockconfig) | Yes| Mock location information, including the interval for reporting the mock locations and the array of the mock locations.| 2111 2112**Error codes** 2113 2114For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 2115 2116| ID| Error Message| 2117| -------- | ---------------------------------------- | 2118|3301000 | Location service is unavailable. | 2119|3301100 | The location switch is off.| 2120 2121**Example** 2122 2123 ```ts 2124 import geoLocationManager from '@ohos.geoLocationManager'; 2125 import BusinessError from "@ohos.base"; 2126 let locations:Array<geoLocationManager.Location> = [ 2127 {"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true}, 2128 {"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true}, 2129 {"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true}, 2130 {"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true}, 2131 {"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true} 2132 ]; 2133 let config:geoLocationManager.LocationMockConfig = {"timeInterval": 5, "locations": locations}; 2134 try { 2135 geoLocationManager.enableLocationMock(); 2136 geoLocationManager.setMockedLocations(config); 2137 } catch (err) { 2138 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 2139 } 2140 ``` 2141 2142 2143## geoLocationManager.enableReverseGeocodingMock 2144 2145enableReverseGeocodingMock(): void; 2146 2147Enables the mock reverse geocoding function. 2148 2149**System capability**: SystemCapability.Location.Location.Core 2150 2151**System API**: This is a system API. 2152 2153**Error codes** 2154 2155For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 2156 2157| ID| Error Message| 2158| -------- | ---------------------------------------- | 2159|3301000 | Location service is unavailable. | 2160 2161**Example** 2162 2163 ```ts 2164 import geoLocationManager from '@ohos.geoLocationManager'; 2165 import BusinessError from "@ohos.base"; 2166 try { 2167 geoLocationManager.enableReverseGeocodingMock(); 2168 } catch (err) { 2169 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 2170 } 2171 ``` 2172 2173 2174## geoLocationManager.disableReverseGeocodingMock 2175 2176disableReverseGeocodingMock(): void; 2177 2178Disables the mock geocoding function. 2179 2180**System capability**: SystemCapability.Location.Location.Core 2181 2182**System API**: This is a system API. 2183 2184**Error codes** 2185 2186For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 2187 2188| ID| Error Message| 2189| -------- | ---------------------------------------- | 2190|3301000 | Location service is unavailable. | 2191 2192**Example** 2193 2194 ```ts 2195 import geoLocationManager from '@ohos.geoLocationManager'; 2196 import BusinessError from "@ohos.base"; 2197 try { 2198 geoLocationManager.disableReverseGeocodingMock(); 2199 } catch (err) { 2200 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 2201 } 2202 ``` 2203 2204 2205## geoLocationManager.setReverseGeocodingMockInfo 2206 2207setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>): void; 2208 2209Sets 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. 2210 2211This API can be invoked only after [geoLocationManager.enableReverseGeocodingMock](#geolocationmanagerenablereversegeocodingmock) is called. 2212 2213**System capability**: SystemCapability.Location.Location.Core 2214 2215**System API**: This is a system API. 2216 2217**Parameters** 2218 2219 | Name| Type| Mandatory| Description| 2220 | -------- | -------- | -------- | -------- | 2221 | mockInfos | Array<[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)> | Yes| Array of information of the mock reverse geocoding function, including a location and a geographical name.| 2222 2223**Error codes** 2224 2225For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 2226 2227| ID| Error Message| 2228| -------- | ---------------------------------------- | 2229|3301000 | Location service is unavailable. | 2230 2231**Example** 2232 2233 ```ts 2234 import geoLocationManager from '@ohos.geoLocationManager'; 2235 import BusinessError from "@ohos.base"; 2236 let mockInfos:Array<geoLocationManager.ReverseGeocodingMockInfo> = [ 2237 {"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "isFromMock": true}}, 2238 {"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "isFromMock": true}}, 2239 {"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "isFromMock": true}}, 2240 {"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "isFromMock": true}}, 2241 {"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "isFromMock": true}}, 2242 ]; 2243 try { 2244 geoLocationManager.enableReverseGeocodingMock(); 2245 geoLocationManager.setReverseGeocodingMockInfo(mockInfos); 2246 } catch (err) { 2247 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 2248 } 2249 ``` 2250 2251 2252## geoLocationManager.isLocationPrivacyConfirmed 2253 2254isLocationPrivacyConfirmed(type: LocationPrivacyType): boolean; 2255 2256Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications. 2257 2258**System API**: This is a system API. 2259 2260**System capability**: SystemCapability.Location.Location.Core 2261 2262**Parameters** 2263 2264 | Name| Type| Mandatory| Description| 2265 | -------- | -------- | -------- | -------- | 2266 | 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.| 2267 2268**Return value** 2269 2270 | Name| Type| Mandatory| Description| 2271 | -------- | -------- | -------- | -------- | 2272 | boolean | boolean | NA | Whether the user agrees with the privacy statement.| 2273 2274**Error codes** 2275 2276For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 2277 2278| ID| Error Message| 2279| -------- | ---------------------------------------- | 2280|3301000 | Location service is unavailable. | 2281 2282**Example** 2283 2284 ```ts 2285 import geoLocationManager from '@ohos.geoLocationManager'; 2286 import BusinessError from "@ohos.base"; 2287 try { 2288 let isConfirmed = geoLocationManager.isLocationPrivacyConfirmed(1); 2289 } catch (err) { 2290 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 2291 } 2292 ``` 2293 2294 2295## geoLocationManager.setLocationPrivacyConfirmStatus 2296 2297setLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean): void; 2298 2299Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications. 2300 2301**System API**: This is a system API. 2302 2303**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS 2304 2305**System capability**: SystemCapability.Location.Location.Core 2306 2307**Parameters** 2308 2309 | Name| Type| Mandatory| Description| 2310 | -------- | -------- | -------- | -------- | 2311 | 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.| 2312 | isConfirmed | boolean | Yes| Whether the user agrees with the privacy statement.| 2313 2314**Error codes** 2315 2316For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 2317 2318| ID| Error Message| 2319| -------- | ---------------------------------------- | 2320|3301000 | Location service is unavailable. | 2321 2322**Example** 2323 2324 ```ts 2325 import geoLocationManager from '@ohos.geoLocationManager'; 2326 import BusinessError from "@ohos.base"; 2327 try { 2328 geoLocationManager.setLocationPrivacyConfirmStatus(1, true); 2329 } catch (err) { 2330 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 2331 } 2332 ``` 2333 2334 2335## geoLocationManager.getLocatingRequiredData<sup>10+</sup> 2336 2337getLocatingRequiredData(config: LocatingRequiredDataConfig): Promise<Array<LocatingRequiredData>>; 2338 2339Obtains the required data of the location service. This API uses a promise to return the result. 2340 2341**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 2342 2343**System capability**: SystemCapability.Location.Location.Core 2344 2345**System API**: This is a system API. 2346 2347**Parameters** 2348 2349 | Name| Type| Mandatory| Description| 2350 | -------- | -------- | -------- | -------- | 2351 | config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.| 2352 2353**Return value** 2354 2355 | Name| Type| Mandatory| Description| 2356 | -------- | -------- | -------- | -------- | 2357 | Promise<Array<[LocatingRequiredData](#locatingrequireddata10)>> | [LocatingRequiredData](#locatingrequireddata10) | NA | Promise used to receive the required data of the location service, such as the Wi-Fi and Bluetooth scanning information.| 2358 2359**Error codes** 2360 2361For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md). 2362 2363| ID| Error Message| 2364| -------- | ---------------------------------------- | 2365|3301800 | Failed to start WiFi or Bluetooth scanning. | 2366 2367**Example** 2368 2369 ```ts 2370 import geoLocationManager from '@ohos.geoLocationManager'; 2371 import BusinessError from "@ohos.base"; 2372 let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; 2373 try { 2374 geoLocationManager.getLocatingRequiredData(config).then((result) => { 2375 console.log('getLocatingRequiredData return: ' + JSON.stringify(result)); 2376 }) 2377 .catch((error:number) => { 2378 console.log('promise, getLocatingRequiredData: error=' + JSON.stringify(error)); 2379 }); 2380 } catch (err) { 2381 console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 2382 } 2383 ``` 2384