js-apis-geoLocationManager.md 95.2 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.geoLocationManager (Geolocation Manager)
S
shawn_he 已提交
2

S
shawn_he 已提交
3
The **geoLocationManager** module provides location services such as Global Navigation Satellite System (GNSS)-based positioning, network positioning, geofencing, as well as geocoding and reverse geocoding.
S
shawn_he 已提交
4

S
shawn_he 已提交
5 6
> **NOTE**
>
S
shawn_he 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
> 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.

## Applying for Permissions

Before 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.

The system provides the following location permissions:
- ohos.permission.LOCATION

- ohos.permission.APPROXIMATELY_LOCATION

- ohos.permission.LOCATION_IN_BACKGROUND

If your application needs to access the device location information, it must first apply for required permissions. Specifically speaking:

S
shawn_he 已提交
22
API versions earlier than 9: Apply for **ohos.permission.LOCATION**.
S
shawn_he 已提交
23

S
shawn_he 已提交
24
API 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.
S
shawn_he 已提交
25

S
shawn_he 已提交
26 27
| API Version| Location Permission| Permission Application Result| Location Accuracy|
| -------- | -------- | -------- | -------- |
S
shawn_he 已提交
28 29 30 31
| Earlier than 9| ohos.permission.LOCATION | Success| Location accurate to meters|
| 9 and later| ohos.permission.LOCATION | Failure| No location obtained|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters|
S
shawn_he 已提交
32

S
shawn_he 已提交
33
If 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.
S
shawn_he 已提交
34 35 36 37 38 39 40 41 42 43 44

You can declare the required permission in your application's configuration file. For details, see [Access Control (Permission) Development](../../security/accesstoken-guidelines.md).


## Modules to Import

```ts
import geoLocationManager from '@ohos.geoLocationManager';
```


S
shawn_he 已提交
45 46 47 48 49 50 51 52 53 54 55
## ReverseGeoCodeRequest

Defines a reverse geocoding request.

**System capability**: SystemCapability.Location.Location.Geocoder

| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| 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**.|
| 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**.|
S
shawn_he 已提交
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.|
S
shawn_he 已提交
57 58 59 60 61 62 63 64 65 66 67 68


## GeoCodeRequest

Defines a geocoding request.

**System capability**: SystemCapability.Location.Location.Geocoder

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| description | string | Yes| Yes| Location description, for example, **No. xx, xx Road, Pudong New District, Shanghai**.|
S
shawn_he 已提交
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.|
S
shawn_he 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| 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**.|
| minLongitude | number | Yes| Yes| Minimum longitude. The value ranges from **-180** to **180**.|
| maxLatitude | number | Yes| Yes| Maximum latitude. The value ranges from **-90** to **90**.|
| maxLongitude | number | Yes| Yes| Maximum longitude. The value ranges from **-180** to **180**.|


## GeoAddress

Defines a geographic location.

**System capability**: SystemCapability.Location.Location.Geocoder

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| 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**.|
| 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**.|
| locale | string | Yes| No | Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| placeName | string | Yes| No | Landmark of the location.|
| countryCode | string | Yes| No | Country code.|
| countryName | string| Yes| No| Country name.|
| administrativeArea | string | Yes| No| Administrative region name.|
| subAdministrativeArea | string | Yes| No| Sub-administrative region name.|
| locality | string | Yes| No| Locality information.|
| subLocality | string | Yes| No| Sub-locality information.|
| roadName | string | Yes| No|Road name.|
| subRoadName | string | Yes| No| Auxiliary road information.|
| premises | string| Yes| No|House information.|
| postalCode | string | Yes| No| Postal code.|
| phoneNumber | string | Yes| No| Phone number.|
| addressUrl | string | Yes| No| Website URL.|
| descriptions | Array<string> | Yes| No| Additional descriptions.|
S
shawn_he 已提交
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.|
S
shawn_he 已提交
102
| isFromMock | Boolean | Yes| No| Whether the geographical name is from the mock reverse geocoding function.<br>**System API**: This is a system API.|
S
shawn_he 已提交
103 104 105 106 107 108 109 110 111 112


## LocationRequest

Defines a location request.

**System capability**: SystemCapability.Location.Location.Core

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
113 114 115 116 117
| 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).|
| 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).|
| 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**.|
| 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**.|
| 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**.|
S
shawn_he 已提交
118 119 120 121 122 123 124 125 126 127


## CurrentLocationRequest

Defines the current location request.

**System capability**: SystemCapability.Location.Location.Core

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
128 129 130
| 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).|
| 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).|
| 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**.|
S
shawn_he 已提交
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**.|
S
shawn_he 已提交
132 133 134 135 136 137 138 139 140 141


## SatelliteStatusInfo

Defines the satellite status information.

**System capability**: SystemCapability.Location.Location.Gnss

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
142 143 144
| satellitesNumber | number | Yes| No| Number of satellites. The specified value must be greater than or equal to **0**.|
| satelliteIds | Array&lt;number&gt; | Yes| No| Array of satellite IDs. The specified value must be greater than or equal to **0**.|
| carrierToNoiseDensitys | Array&lt;number&gt; | Yes| No| Carrier-to-noise density ratio, that is, **cn0**. The specified value must be greater than **0**.|
S
shawn_he 已提交
145 146
| altitudes | Array&lt;number&gt; | Yes| No| Satellite altitude angle information. The value ranges from **-90** to **90**, in degrees.|
| azimuths | Array&lt;number&gt; | Yes| No| Azimuth information. The value ranges from **0** to **360**, in degrees.|
S
shawn_he 已提交
147
| carrierFrequencies | Array&lt;number&gt; | Yes| No| Carrier frequency, in Hz. The specified value must be greater than or equal to **0**.|
S
shawn_he 已提交
148 149 150 151


## CachedGnssLocationsRequest

S
shawn_he 已提交
152
Defines a request for reporting cached GNSS locations.
S
shawn_he 已提交
153 154 155 156 157

**System capability**: SystemCapability.Location.Location.Gnss

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
158
| reportingPeriodSec | number | Yes| Yes| Interval for reporting the cached GNSS locations, in milliseconds. The specified value must be greater than **0**.|
S
shawn_he 已提交
159 160 161 162 163 164 165 166 167 168 169 170 171
| 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.|


## Geofence

Defines a GNSS geofence. Currently, only circular geofences are supported.

**System capability**: SystemCapability.Location.Location.Geofence

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| latitude | number | Yes| Yes|Latitude information. The value ranges from **-90** to **90**.|
| longitude | number | Yes|Yes| Longitude information. The value ranges from **-180** to **180**.|
S
shawn_he 已提交
172 173
| radius | number | Yes|Yes| Radius of a circular geofence, in meters. The specified value must be greater than **0**.|
| expiration | number | Yes|Yes| Expiration period of a geofence, in milliseconds. The specified value must be greater than **0**.|
S
shawn_he 已提交
174 175 176 177


## GeofenceRequest

S
shawn_he 已提交
178
Defines a GNSS geofencing request.
S
shawn_he 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216

**System capability**: SystemCapability.Location.Location.Geofence

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes |  Location scenario.|
| geofence |  [Geofence](#geofence)| Yes| Yes |  Geofence information.|


## LocationCommand

Defines an extended command.

**System capability**: SystemCapability.Location.Location.Core

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| scenario | [LocationRequestScenario](#locationrequestscenario)  | Yes| Yes | Location scenario.|
| command | string | Yes| Yes | Extended command, in the string format.|


## Location

Defines a location.

**System capability**: SystemCapability.Location.Location.Core

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| 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**.|
| 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**.|
| altitude | number | Yes| No| Location altitude, in meters.|
| accuracy | number | Yes| No| Location accuracy, in meters.|
| speed | number | Yes| No|Speed, in m/s.|
| timeStamp | number | Yes| No| Location timestamp in the UTC format.|
| direction | number | Yes| No| Direction information. The value ranges from **0** to **360**, in degrees.|
| timeSinceBoot | number | Yes| No| Location timestamp since boot.|
| additions | Array&lt;string&gt; | Yes| No| Additional description.|
S
shawn_he 已提交
217
| additionSize | number | Yes| No| Number of additional descriptions. The specified value must be greater than or equal to **0**. |
S
shawn_he 已提交
218 219 220 221 222
| isFromMock | Boolean | Yes| No| Whether the location information is from the mock location function.<br>**System API**: This is a system API.|


## ReverseGeocodingMockInfo

S
shawn_he 已提交
223
Defines the configuration of the mock reverse geocoding function.
S
shawn_he 已提交
224 225 226

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
227
**System API**: This is a system API.
S
shawn_he 已提交
228 229 230 231

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| location |  [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Yes| Latitude and longitude information.|
S
shawn_he 已提交
232
| geoAddress |  [GeoAddress](#geoaddress) | Yes| Yes|Geographical name.|
S
shawn_he 已提交
233 234 235 236


## LocationMockConfig

S
shawn_he 已提交
237
Defines the configuration of the mock location function.
S
shawn_he 已提交
238 239 240

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
241
**System API**: This is a system API.
S
shawn_he 已提交
242 243 244

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
245
| timeInterval | number | Yes| Yes| Time interval at which mock locations are reported, in seconds.|
S
shawn_he 已提交
246 247 248 249 250
| locations | Array&lt;[Location](#location)&gt; | Yes| Yes| Array of mocked locations.|


## CountryCode

S
shawn_he 已提交
251
Defines the country code information.
S
shawn_he 已提交
252 253 254 255 256 257 258 259 260

**System capability**: SystemCapability.Location.Location.Core

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| country | string | Yes| No| Country code.|
| type |  [CountryCodeType](#countrycodetype) | Yes| No| Country code source.|


S
shawn_he 已提交
261 262 263 264 265 266 267 268 269 270 271 272
## LocatingRequiredDataConfig<sup>10+</sup>

Defines the configuration for obtaining the required data of the location service.

**System capability**: SystemCapability.Location.Location.Core

**System API**: This is a system API.

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| type | [LocatingRequiredDataType](#locatingrequireddatatype10) | Yes| Yes| Type of the required data.|
| needStartScan |  boolean | Yes| Yes| Whether to initiate scanning.|
S
shawn_he 已提交
273 274
| scanInterval |  number | Yes| Yes| Scanning interval, in milliseconds. The specified value must be greater than **0**. The default value is **10000**.|
| scanTimeout |  number | Yes| Yes| Scanning timeout interval, in milliseconds. The value ranges from **0** to **600000**. The default value is **10000**.|
S
shawn_he 已提交
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323


## LocatingRequiredData<sup>10+</sup>

Defines 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.

**System capability**: SystemCapability.Location.Location.Core

**System API**: This is a system API.

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| wifiData | [WifiScanInfo](#wifiscaninfo10) | Yes| No| Wi-Fi scanning result.|
| bluetoothData |  [BluetoothScanInfo](#bluetoothscaninfo10) | Yes| No| Bluetooth scanning result.|


## WifiScanInfo<sup>10+</sup>

Defines the Wi-Fi scanning information, including the SSID, BSSID, and RSSI of the scanned Wi-Fi hotspot.

**System capability**: SystemCapability.Location.Location.Core

**System API**: This is a system API.

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| ssid | string | Yes| No| Service set identifier (SSID) of a Wi-Fi hotspot, in UTF-8 format.|
| bssid | string | Yes| No| Base station subsystem identifier (BSSID) of a Wi-Fi hotspot.|
| rssi | number | Yes| No| Received signal strength indicator (RSSI) of a Wi-Fi hotspot, in dBm.|
| frequency | number | Yes| No| Frequency of a Wi-Fi hotspot.|
| timestamp | number | Yes| No| Scanning timestamp.|


## BluetoothScanInfo<sup>10+</sup>

Defines the Bluetooth scanning information.

**System capability**: SystemCapability.Location.Location.Core

**System API**: This is a system API.

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| deviceName | string | Yes| No| Name of a Bluetooth device.|
| macAddress | string | Yes| No| MAC address of a Bluetooth device.|
| rssi | number | Yes| No| Signal strength of a Bluetooth device, in dBm.|
| timestamp | number | Yes| No| Scanning timestamp.|


S
shawn_he 已提交
324 325 326 327 328 329 330 331 332
## LocationRequestPriority

Sets the priority of the location request.

**System capability**: SystemCapability.Location.Location.Core

| Name| Value| Description|
| -------- | -------- | -------- |
| UNSET | 0x200 | Priority unspecified.<br>If this option is used, [LocationRequestPriority](#locationrequestpriority) is invalid.|
S
shawn_he 已提交
333 334
| 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.|
| 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.|
S
shawn_he 已提交
335 336 337 338 339
| 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.|


## LocationRequestScenario

S
shawn_he 已提交
340
  Sets the scenario of the location request.
S
shawn_he 已提交
341 342 343 344 345

**System capability**: SystemCapability.Location.Location.Core

| Name| Value| Description|
| -------- | -------- | -------- |
S
shawn_he 已提交
346
| UNSET | 0x300 | Scenario unspecified.<br>If this option is used, [LocationRequestScenario](#locationrequestscenario) is invalid.|
S
shawn_he 已提交
347 348 349 350 351
| 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.|
| 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.|
| 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.|
| 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.|
| 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.|
S
shawn_he 已提交
352 353 354 355 356 357 358 359


## LocationPrivacyType

Defines the privacy statement type.

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
360
**System API**: This is a system API.
S
shawn_he 已提交
361 362 363 364

| Name| Value| Description|
| -------- | -------- | -------- |
| OTHERS | 0 | Other scenarios. Reserved field.|
S
shawn_he 已提交
365
| STARTUP | 1 | Privacy statement displayed in the startup wizard. The user needs to choose whether to agree with the statement.|
S
shawn_he 已提交
366 367 368 369 370
| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.|


## CountryCodeType

S
shawn_he 已提交
371
Defines the country code source type.
S
shawn_he 已提交
372 373 374 375 376 377 378 379 380 381 382

**System capability**: SystemCapability.Location.Location.Core

| Name| Value| Description|
| -------- | -------- | -------- |
| COUNTRY_CODE_FROM_LOCALE | 1 | Country code obtained from the language configuration of the globalization module.|
| COUNTRY_CODE_FROM_SIM | 2 | Country code obtained from the SIM card.|
| COUNTRY_CODE_FROM_LOCATION | 3 | Country code obtained using the reverse geocoding function based on the user's location information.|
| COUNTRY_CODE_FROM_NETWORK | 4 | Country code obtained from the cellular network registration information.|


S
shawn_he 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396
## LocatingRequiredDataType<sup>10+</sup>

Defines the type of the required data of the location service.

**System capability**: SystemCapability.Location.Location.Core

**System API**: This is a system API.

| Name| Value| Description|
| -------- | -------- | -------- |
| WIFI  | 1 | Wi-Fi scanning information.|
| BLUETOOTH | 2 | Bluetooth scanning information.|


S
shawn_he 已提交
397
## geoLocationManager.on('locationChange')
S
shawn_he 已提交
398

S
shawn_he 已提交
399
on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Location&gt;): void
S
shawn_he 已提交
400

S
shawn_he 已提交
401
Subscribes to location change events with a location request initiated.
S
shawn_he 已提交
402

S
shawn_he 已提交
403
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
404 405 406 407 408

**System capability**: SystemCapability.Location.Location.Core

**Parameters**

S
shawn_he 已提交
409 410
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
411
  | type | string | Yes| Event type. The value **locationChange** indicates a location change.|
S
shawn_he 已提交
412
  | request |  [LocationRequest](#locationrequest) | Yes| Location request.|
S
shawn_he 已提交
413
  | callback | Callback&lt;[Location](#location)&gt; | Yes| Callback used to receive location change events.|
S
shawn_he 已提交
414 415 416

**Error codes**

S
shawn_he 已提交
417
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
418

S
shawn_he 已提交
419 420 421 422 423
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
424 425

**Example**
S
shawn_he 已提交
426

S
shawn_he 已提交
427 428
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
429 430 431
  import BusinessError from "@ohos.base";
  let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
  let locationChange = (location:geoLocationManager.Location):void => {
S
shawn_he 已提交
432 433
      console.log('locationChanger: data: ' + JSON.stringify(location));
  };
S
shawn_he 已提交
434
  try {
S
shawn_he 已提交
435
      geoLocationManager.on('locationChange', requestInfo, locationChange);
S
shawn_he 已提交
436
  } catch (err) {
S
shawn_he 已提交
437
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
438
  }
S
shawn_he 已提交
439
  
S
shawn_he 已提交
440 441 442
  ```


S
shawn_he 已提交
443
## geoLocationManager.off('locationChange')
S
shawn_he 已提交
444

S
shawn_he 已提交
445
off(type: 'locationChange', callback?: Callback&lt;Location&gt;): void
S
shawn_he 已提交
446

S
shawn_he 已提交
447
Unsubscribes from location change events with the corresponding location request deleted.
S
shawn_he 已提交
448

S
shawn_he 已提交
449
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
450 451 452 453 454

**System capability**: SystemCapability.Location.Location.Core

**Parameters**

S
shawn_he 已提交
455 456
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
457
  | type | string | Yes| Event type. The value **locationChange** indicates a location change.|
S
shawn_he 已提交
458
  | callback | Callback&lt;[Location](#location)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
459 460 461

**Error codes**

S
shawn_he 已提交
462
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
463

S
shawn_he 已提交
464 465 466 467 468
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
469 470

**Example**
S
shawn_he 已提交
471

S
shawn_he 已提交
472 473
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
474 475 476 477
  import BusinessError from "@ohos.base";
  let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
  let locationChange = (location:geoLocationManager.Location):void => {
    console.log('locationChanger: data: ' + JSON.stringify(location));
S
shawn_he 已提交
478
  };
S
shawn_he 已提交
479
  try {
S
shawn_he 已提交
480 481
      geoLocationManager.on('locationChange', requestInfo, locationChange);
      geoLocationManager.off('locationChange', locationChange);
S
shawn_he 已提交
482
  } catch (err) {
S
shawn_he 已提交
483
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
484 485 486 487
  }
  ```


S
shawn_he 已提交
488
## geoLocationManager.on('locationEnabledChange')
S
shawn_he 已提交
489

S
shawn_he 已提交
490
on(type: 'locationEnabledChange', callback: Callback&lt;boolean&gt;): void
S
shawn_he 已提交
491

S
shawn_he 已提交
492
Subscribes to location service status change events.
S
shawn_he 已提交
493 494 495 496 497

**System capability**: SystemCapability.Location.Location.Core

**Parameters**

S
shawn_he 已提交
498 499
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
500 501
  | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change.|
  | callback | Callback&lt;boolean&gt; | Yes| Callback used to receive location service status change events.|
S
shawn_he 已提交
502 503 504

**Error codes**

S
shawn_he 已提交
505
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
506

S
shawn_he 已提交
507 508 509
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
510 511

**Example**
S
shawn_he 已提交
512

S
shawn_he 已提交
513 514
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
515 516
  import BusinessError from "@ohos.base";
  let locationEnabledChange = (state:boolean):void => {
S
shawn_he 已提交
517 518 519 520 521
      console.log('locationEnabledChange: ' + JSON.stringify(state));
  }
  try {
      geoLocationManager.on('locationEnabledChange', locationEnabledChange);
  } catch (err) {
S
shawn_he 已提交
522
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
523
  }
S
shawn_he 已提交
524 525 526
  ```


S
shawn_he 已提交
527
## geoLocationManager.off('locationEnabledChange')
S
shawn_he 已提交
528

S
shawn_he 已提交
529
off(type: 'locationEnabledChange', callback?: Callback&lt;boolean&gt;): void;
S
shawn_he 已提交
530

S
shawn_he 已提交
531
Unsubscribes from location service status change events.
S
shawn_he 已提交
532 533 534

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
535
**Parameters**
S
shawn_he 已提交
536

S
shawn_he 已提交
537 538
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
539
  | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change.|
S
shawn_he 已提交
540
  | callback | Callback&lt;boolean&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
541 542 543

**Error codes**

S
shawn_he 已提交
544
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
545

S
shawn_he 已提交
546 547 548
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
549 550

**Example**
S
shawn_he 已提交
551

S
shawn_he 已提交
552 553
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
554 555
  import BusinessError from "@ohos.base";
  let locationEnabledChange = (state:boolean):void => {
S
shawn_he 已提交
556 557 558 559 560 561
      console.log('locationEnabledChange: state: ' + JSON.stringify(state));
  }
  try {
      geoLocationManager.on('locationEnabledChange', locationEnabledChange);
      geoLocationManager.off('locationEnabledChange', locationEnabledChange);
  } catch (err) {
S
shawn_he 已提交
562
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
563
  }
S
shawn_he 已提交
564 565 566
  ```


S
shawn_he 已提交
567
## geoLocationManager.on('cachedGnssLocationsChange')
S
shawn_he 已提交
568

S
shawn_he 已提交
569
on(type: 'cachedGnssLocationsChange', request: CachedGnssLocationsRequest, callback: Callback&lt;Array&lt;Location&gt;&gt;): void;
S
shawn_he 已提交
570

S
shawn_he 已提交
571
Subscribes to cached GNSS location reports.
S
shawn_he 已提交
572

S
shawn_he 已提交
573
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
574

S
shawn_he 已提交
575
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
576 577 578

**Parameters**

S
shawn_he 已提交
579 580 581 582
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.|
  | request |  [CachedGnssLocationsRequest](#cachedgnsslocationsrequest) | Yes| Request for reporting cached GNSS location.|
S
shawn_he 已提交
583
  | callback | Callback&lt;boolean&gt; | Yes| Callback used to receive cached GNSS locations.|
S
shawn_he 已提交
584 585 586

**Error codes**

S
shawn_he 已提交
587
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
588

S
shawn_he 已提交
589 590 591 592 593
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
594 595

**Example**
S
shawn_he 已提交
596

S
shawn_he 已提交
597 598
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
599 600
  import BusinessError from "@ohos.base";
  let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => {
S
shawn_he 已提交
601 602
      console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
  }
S
shawn_he 已提交
603
  let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
S
shawn_he 已提交
604
  try {
S
shawn_he 已提交
605
      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
S
shawn_he 已提交
606
  } catch (err) {
S
shawn_he 已提交
607
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
608 609 610 611
  }
  ```


S
shawn_he 已提交
612
## geoLocationManager.off('cachedGnssLocationsChange')
S
shawn_he 已提交
613

S
shawn_he 已提交
614
off(type: 'cachedGnssLocationsChange', callback?: Callback&lt;Array&lt;Location&gt;&gt;): void;
S
shawn_he 已提交
615

S
shawn_he 已提交
616
Unsubscribes from cached GNSS location reports.
S
shawn_he 已提交
617

S
shawn_he 已提交
618
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
619

S
shawn_he 已提交
620
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
621

S
shawn_he 已提交
622
**Parameters**
S
shawn_he 已提交
623

S
shawn_he 已提交
624 625 626 627
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.|
  | callback | Callback&lt;boolean&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
628 629 630

**Error codes**

S
shawn_he 已提交
631
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
632

S
shawn_he 已提交
633 634 635 636 637
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
638 639

**Example**
S
shawn_he 已提交
640

S
shawn_he 已提交
641 642
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
643 644
  import BusinessError from "@ohos.base";
  let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => {
S
shawn_he 已提交
645 646
      console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
  }
S
shawn_he 已提交
647
  let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
S
shawn_he 已提交
648 649 650 651
  try {
      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
      geoLocationManager.off('cachedGnssLocationsChange');
  } catch (err) {
S
shawn_he 已提交
652
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
653
  }
S
shawn_he 已提交
654 655 656
  ```


S
shawn_he 已提交
657
## geoLocationManager.on('satelliteStatusChange')
S
shawn_he 已提交
658

S
shawn_he 已提交
659
on(type: 'satelliteStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;): void;
S
shawn_he 已提交
660

S
shawn_he 已提交
661
Subscribes to GNSS satellite status change events.
S
shawn_he 已提交
662

S
shawn_he 已提交
663
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
664

S
shawn_he 已提交
665
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
666 667 668

**Parameters**

S
shawn_he 已提交
669 670
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
671 672
  | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change.|
  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | Yes| Callback used to receive GNSS satellite status change events.|
S
shawn_he 已提交
673 674 675

**Error codes**

S
shawn_he 已提交
676
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
677

S
shawn_he 已提交
678 679 680 681
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
682 683

**Example**
S
shawn_he 已提交
684

S
shawn_he 已提交
685 686
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
687 688
  import BusinessError from "@ohos.base";
  let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => {
S
shawn_he 已提交
689 690 691 692 693 694
      console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
  }

  try {
      geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
  } catch (err) {
S
shawn_he 已提交
695
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
696
  }
S
shawn_he 已提交
697 698 699
  ```


S
shawn_he 已提交
700
## geoLocationManager.off('satelliteStatusChange')
S
shawn_he 已提交
701

S
shawn_he 已提交
702
off(type: 'satelliteStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;): void;
S
shawn_he 已提交
703

S
shawn_he 已提交
704
Unsubscribes from GNSS satellite status change events.
S
shawn_he 已提交
705

S
shawn_he 已提交
706
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
707

S
shawn_he 已提交
708
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
709 710 711

**Parameters**

S
shawn_he 已提交
712 713
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
714
  | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change.|
S
shawn_he 已提交
715
  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
716 717 718

**Error codes**

S
shawn_he 已提交
719
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
720

S
shawn_he 已提交
721 722 723 724
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
725 726


S
shawn_he 已提交
727
**Example**
S
shawn_he 已提交
728

S
shawn_he 已提交
729 730
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
731 732
  import BusinessError from "@ohos.base";
  let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => {
S
shawn_he 已提交
733 734 735 736 737 738
      console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
  }
  try {
      geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
      geoLocationManager.off('satelliteStatusChange', gnssStatusCb);
  } catch (err) {
S
shawn_he 已提交
739
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
740
  }
S
shawn_he 已提交
741 742 743
  ```


S
shawn_he 已提交
744
## geoLocationManager.on('nmeaMessage')
S
shawn_he 已提交
745

S
shawn_he 已提交
746
on(type: 'nmeaMessage', callback: Callback&lt;string&gt;): void;
S
shawn_he 已提交
747

S
shawn_he 已提交
748
Subscribes to GNSS NMEA message change events.
S
shawn_he 已提交
749

S
shawn_he 已提交
750
**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
751

S
shawn_he 已提交
752
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
753 754 755

**Parameters**

S
shawn_he 已提交
756 757
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
758 759
  | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change.|
  | callback | Callback&lt;string&gt; | Yes| Callback used to receive GNSS NMEA message change events.|
S
shawn_he 已提交
760 761 762

**Error codes**

S
shawn_he 已提交
763
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
764

S
shawn_he 已提交
765 766 767 768
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
769 770


S
shawn_he 已提交
771
**Example**
S
shawn_he 已提交
772

S
shawn_he 已提交
773 774
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
775 776
  import BusinessError from "@ohos.base";
  let nmeaCb = (str:string):void => {
S
shawn_he 已提交
777 778
      console.log('nmeaMessage: ' + JSON.stringify(str));
  }
S
shawn_he 已提交
779

S
shawn_he 已提交
780 781 782
  try {
      geoLocationManager.on('nmeaMessage', nmeaCb );
  } catch (err) {
S
shawn_he 已提交
783
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
784 785
  }
  ```
S
shawn_he 已提交
786 787


S
shawn_he 已提交
788
## geoLocationManager.off('nmeaMessage')
S
shawn_he 已提交
789

S
shawn_he 已提交
790
off(type: 'nmeaMessage', callback?: Callback&lt;string&gt;): void;
S
shawn_he 已提交
791

S
shawn_he 已提交
792
Unsubscribes from GNSS NMEA message change events.
S
shawn_he 已提交
793

S
shawn_he 已提交
794
**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
795

S
shawn_he 已提交
796
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
797 798 799

**Parameters**

S
shawn_he 已提交
800 801
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
802
  | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change.|
S
shawn_he 已提交
803
  | callback | Callback&lt;string&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
804 805 806

**Error codes**

S
shawn_he 已提交
807
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
808

S
shawn_he 已提交
809 810 811 812
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
813 814


S
shawn_he 已提交
815
**Example**
S
shawn_he 已提交
816

S
shawn_he 已提交
817 818
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
819 820
  import BusinessError from "@ohos.base";
  let nmeaCb = (str:string):void => {
S
shawn_he 已提交
821 822 823 824 825 826 827
      console.log('nmeaMessage: ' + JSON.stringify(str));
  }

  try {
      geoLocationManager.on('nmeaMessage', nmeaCb);
      geoLocationManager.off('nmeaMessage', nmeaCb);
  } catch (err) {
S
shawn_he 已提交
828
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
829
  }
S
shawn_he 已提交
830 831 832
  ```


S
shawn_he 已提交
833
## geoLocationManager.on('gnssFenceStatusChange')
S
shawn_he 已提交
834

S
shawn_he 已提交
835
on(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
S
shawn_he 已提交
836

S
shawn_he 已提交
837
Subscribes to status change events of the specified geofence.
S
shawn_he 已提交
838

S
shawn_he 已提交
839
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
840 841

**System capability**: SystemCapability.Location.Location.Geofence
S
shawn_he 已提交
842 843 844

**Parameters**

S
shawn_he 已提交
845 846
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
847
  | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.|
S
shawn_he 已提交
848
  | request |  [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
S
shawn_he 已提交
849
  | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
S
shawn_he 已提交
850 851 852

**Error codes**

S
shawn_he 已提交
853
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
854

S
shawn_he 已提交
855 856 857 858 859
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301600 | Failed to operate the geofence.                                     |
S
shawn_he 已提交
860 861

**Example**
S
shawn_he 已提交
862

S
shawn_he 已提交
863 864
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
865
  import wantAgent from '@ohos.app.ability.wantAgent';
S
shawn_he 已提交
866 867 868
  import BusinessError from "@ohos.base";

  let wantAgentInfo:wantAgent.WantAgentInfo = {
S
shawn_he 已提交
869 870 871
      wants: [
          {
              bundleName: "com.example.myapplication",
S
shawn_he 已提交
872
              abilityName: "EntryAbility",
S
shawn_he 已提交
873
              action: "action1"
S
shawn_he 已提交
874 875 876 877
          }
      ],
      operationType: wantAgent.OperationType.START_ABILITY,
      requestCode: 0,
S
shawn_he 已提交
878
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
S
shawn_he 已提交
879 880 881
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
S
shawn_he 已提交
882
    let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
S
shawn_he 已提交
883 884 885
    try {
        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
    } catch (err) {
S
shawn_he 已提交
886
        console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
887
    }
S
shawn_he 已提交
888 889 890 891
  });
  ```


S
shawn_he 已提交
892
## geoLocationManager.off('gnssFenceStatusChange')
S
shawn_he 已提交
893

S
shawn_he 已提交
894
off(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
S
shawn_he 已提交
895

S
shawn_he 已提交
896
Unsubscribes from status change events of the specified geofence.
S
shawn_he 已提交
897

S
shawn_he 已提交
898
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
899

S
shawn_he 已提交
900 901 902
**System capability**: SystemCapability.Location.Location.Geofence

**Parameters**
S
shawn_he 已提交
903

S
shawn_he 已提交
904 905
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
906
  | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.|
S
shawn_he 已提交
907
  | request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
S
shawn_he 已提交
908
  | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
S
shawn_he 已提交
909 910 911

**Error codes**

S
shawn_he 已提交
912
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
913

S
shawn_he 已提交
914 915 916 917 918
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301600 | Failed to operate the geofence.                                     |
S
shawn_he 已提交
919 920

**Example**
S
shawn_he 已提交
921

S
shawn_he 已提交
922 923
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
924
  import wantAgent from '@ohos.app.ability.wantAgent';
S
shawn_he 已提交
925
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
926
  
S
shawn_he 已提交
927
  let wantAgentInfo:wantAgent.WantAgentInfo = {
S
shawn_he 已提交
928 929 930
      wants: [
          {
              bundleName: "com.example.myapplication",
S
shawn_he 已提交
931
              abilityName: "EntryAbility",
S
shawn_he 已提交
932
              action: "action1",
S
shawn_he 已提交
933 934 935 936 937 938 939 940
          }
      ],
      operationType: wantAgent.OperationType.START_ABILITY,
      requestCode: 0,
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
S
shawn_he 已提交
941
    let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};;
S
shawn_he 已提交
942 943 944 945
    try {
        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
        geoLocationManager.off('gnssFenceStatusChange', requestInfo, wantAgentObj);
    } catch (err) {
S
shawn_he 已提交
946
        console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
947
    }
S
shawn_he 已提交
948 949 950 951
  });
  ```


S
shawn_he 已提交
952
## geoLocationManager.on('countryCodeChange')
S
shawn_he 已提交
953

S
shawn_he 已提交
954
on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;): void;
S
shawn_he 已提交
955

S
shawn_he 已提交
956
Subscribes to country code change events.
S
shawn_he 已提交
957 958 959 960 961

**System capability**: SystemCapability.Location.Location.Core

**Parameters**

S
shawn_he 已提交
962 963
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
964 965
  | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change.|
  | callback | Callback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to receive country code change events.|
S
shawn_he 已提交
966 967 968

**Error codes**

S
shawn_he 已提交
969
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
970

S
shawn_he 已提交
971 972 973 974
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301500 | Failed to query the area information.                                       |
S
shawn_he 已提交
975 976


S
shawn_he 已提交
977
**Example**
S
shawn_he 已提交
978

S
shawn_he 已提交
979 980
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
981 982
  import BusinessError from "@ohos.base";
  let callback = (code:geoLocationManager.CountryCode):void => {
S
shawn_he 已提交
983 984 985 986 987 988
      console.log('countryCodeChange: ' + JSON.stringify(code));
  }

  try {
      geoLocationManager.on('countryCodeChange', callback);
  } catch (err) {
S
shawn_he 已提交
989
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
990
  }
S
shawn_he 已提交
991 992 993
  ```


S
shawn_he 已提交
994 995 996
## geoLocationManager.off('countryCodeChange')

off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;): void;
S
shawn_he 已提交
997

S
shawn_he 已提交
998
Unsubscribes from country code change events.
S
shawn_he 已提交
999 1000 1001

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
1002
**Parameters**
S
shawn_he 已提交
1003

S
shawn_he 已提交
1004 1005
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1006
  | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change.|
S
shawn_he 已提交
1007
  | callback | Callback&lt;[CountryCode](#countrycode)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
1008 1009 1010

**Error codes**

S
shawn_he 已提交
1011
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1012

S
shawn_he 已提交
1013 1014 1015 1016
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301500 | Failed to query the area information.                                       |
S
shawn_he 已提交
1017 1018

**Example**
S
shawn_he 已提交
1019

S
shawn_he 已提交
1020 1021
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1022 1023
  import BusinessError from "@ohos.base";
  let callback = (code:geoLocationManager.CountryCode):void => {
S
shawn_he 已提交
1024 1025 1026 1027 1028 1029 1030
      console.log('countryCodeChange: ' + JSON.stringify(code));
  }

  try {
      geoLocationManager.on('countryCodeChange', callback);
      geoLocationManager.off('countryCodeChange', callback);
  } catch (err) {
S
shawn_he 已提交
1031
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1032
  }
S
shawn_he 已提交
1033 1034 1035
  ```


S
shawn_he 已提交
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
## geoLocationManager.on('locatingRequiredDataChange')<sup>10+</sup>

on(type: 'locatingRequiredDataChange', config: LocatingRequiredDataConfig, callback: Callback&lt;Array&lt;LocatingRequiredData&gt;&gt;): void;

Subscribes 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.

**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION

**System capability**: SystemCapability.Location.Location.Core

**System API**: This is a system API.

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.|
  | config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.|
  | callback | Callback&lt;Array&lt;[LocatingRequiredData](#locatingrequireddata10)&gt;&gt; | Yes| Callback used to receive the required data of the location service.|

**Error codes**

For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301800 | Failed to start WiFi or Bluetooth scanning.                            |

**Example**

  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1068 1069
  import BusinessError from "@ohos.base";
  let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => {
S
shawn_he 已提交
1070 1071
      console.log('locatingRequiredDataChange: ' + JSON.stringify(code));
  }
S
shawn_he 已提交
1072
  let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
S
shawn_he 已提交
1073 1074 1075
  try {
      geoLocationManager.on('locatingRequiredDataChange', config, callback);
  } catch (err) {
S
shawn_he 已提交
1076
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
  }
  ```


## geoLocationManager.off('locatingRequiredDataChange')<sup>10+</sup>

off(type: 'locatingRequiredDataChange', callback?: Callback&lt;Array&lt;LocatingRequiredData&gt;&gt;): void;

Unsubscribes from changes in the required data of the location service and stops Wi-Fi and Bluetooth scanning.

**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION

**System capability**: SystemCapability.Location.Location.Core

**System API**: This is a system API.

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.|
  | callback | Callback&lt;Array&lt;[LocatingRequiredData](#locatingrequireddata10)&gt;&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|

**Error codes**

For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).

**Example**

  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1108 1109
  import BusinessError from "@ohos.base";
  let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => {
S
shawn_he 已提交
1110 1111
      console.log('locatingRequiredDataChange: ' + JSON.stringify(code));
  }
S
shawn_he 已提交
1112
  let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
S
shawn_he 已提交
1113 1114 1115 1116
  try {
      geoLocationManager.on('locatingRequiredDataChange', config, callback);
      geoLocationManager.off('locatingRequiredDataChange', callback);
  } catch (err) {
S
shawn_he 已提交
1117
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1118 1119 1120
  }
  ```

S
shawn_he 已提交
1121

S
shawn_he 已提交
1122
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
1123

S
shawn_he 已提交
1124
getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;Location&gt;): void
S
shawn_he 已提交
1125

S
shawn_he 已提交
1126
Obtains the current location. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
1127

S
shawn_he 已提交
1128
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1129 1130

**System capability**: SystemCapability.Location.Location.Core
S
shawn_he 已提交
1131 1132 1133

**Parameters**

S
shawn_he 已提交
1134 1135 1136
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [CurrentLocationRequest](#currentlocationrequest) | Yes| Location request.|
S
shawn_he 已提交
1137
  | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to receive the current location.|
S
shawn_he 已提交
1138 1139 1140

**Error codes**

S
shawn_he 已提交
1141
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1142

S
shawn_he 已提交
1143 1144 1145 1146 1147
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
1148 1149

**Example**
S
shawn_he 已提交
1150

S
shawn_he 已提交
1151 1152
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1153 1154 1155
  import BusinessError from "@ohos.base";
  let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
  let locationChange = (err:BusinessError.BusinessError, location:geoLocationManager.Location):void => {
S
shawn_he 已提交
1156
      if (err) {
S
shawn_he 已提交
1157
          console.log('locationChanger: err=' + JSON.stringify(err));
S
shawn_he 已提交
1158
      }
S
shawn_he 已提交
1159 1160 1161 1162 1163 1164 1165 1166
      if (location) {
          console.log('locationChanger: location=' + JSON.stringify(location));
      }
  };

  try {
      geoLocationManager.getCurrentLocation(requestInfo, locationChange);
  } catch (err) {
S
shawn_he 已提交
1167
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1168
  }
S
shawn_he 已提交
1169 1170
  ```

S
shawn_he 已提交
1171
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
1172

S
shawn_he 已提交
1173
getCurrentLocation(callback: AsyncCallback&lt;Location&gt;): void;
S
shawn_he 已提交
1174

S
shawn_he 已提交
1175
Obtains the current location. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
1176

S
shawn_he 已提交
1177
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1178 1179 1180

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
1181
**Parameters**
S
shawn_he 已提交
1182

S
shawn_he 已提交
1183 1184
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1185
  | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to receive the current location.|
S
shawn_he 已提交
1186 1187 1188

**Error codes**

S
shawn_he 已提交
1189
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1190

S
shawn_he 已提交
1191 1192 1193 1194 1195
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
1196 1197

**Example**
S
shawn_he 已提交
1198

S
shawn_he 已提交
1199 1200
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1201 1202
  import BusinessError from "@ohos.base";
  let locationChange = (err:BusinessError.BusinessError, location:geoLocationManager.Location) => {
S
shawn_he 已提交
1203 1204
      if (err) {
          console.log('locationChanger: err=' + JSON.stringify(err));
S
shawn_he 已提交
1205
      }
S
shawn_he 已提交
1206 1207 1208 1209 1210 1211 1212 1213
      if (location) {
          console.log('locationChanger: location=' + JSON.stringify(location));
      }
  };

  try {
      geoLocationManager.getCurrentLocation(locationChange);
  } catch (err) {
S
shawn_he 已提交
1214
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1215
  }
S
shawn_he 已提交
1216 1217
  ```

S
shawn_he 已提交
1218
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
1219

S
shawn_he 已提交
1220
getCurrentLocation(request?: CurrentLocationRequest): Promise&lt;Location&gt;
S
shawn_he 已提交
1221

S
shawn_he 已提交
1222
Obtains the current location. This API uses a promise to return the result. 
S
shawn_he 已提交
1223

S
shawn_he 已提交
1224
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1225 1226 1227 1228 1229

**System capability**: SystemCapability.Location.Location.Core

**Parameters**

S
shawn_he 已提交
1230 1231 1232 1233 1234 1235 1236 1237 1238
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.|

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;[Location](#location)&gt;  | [Location](#location) | NA | Promise used to return the current location.|
S
shawn_he 已提交
1239 1240 1241

**Error codes**

S
shawn_he 已提交
1242
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1243

S
shawn_he 已提交
1244 1245 1246 1247 1248
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
1249 1250

**Example**
S
shawn_he 已提交
1251

S
shawn_he 已提交
1252 1253
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1254 1255
  import BusinessError from "@ohos.base";
  let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
S
shawn_he 已提交
1256 1257 1258 1259
  try {
      geoLocationManager.getCurrentLocation(requestInfo).then((result) => {
          console.log('current location: ' + JSON.stringify(result));
      })  
S
shawn_he 已提交
1260
      .catch((error:number) => {
S
shawn_he 已提交
1261 1262 1263
          console.log('promise, getCurrentLocation: error=' + JSON.stringify(error));
      });
  } catch (err) {
S
shawn_he 已提交
1264
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
  }
  ```


## geoLocationManager.getLastLocation

getLastLocation(): Location

Obtains the last location.

S
shawn_he 已提交
1275
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286

**System capability**: SystemCapability.Location.Location.Core

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Location  | [Location](#location) | NA | Location information.|

**Error codes**

S
shawn_he 已提交
1287
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1288 1289 1290 1291 1292 1293 1294 1295

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.  |
|3301100 | The location switch is off.  |
|3301200 |Failed to obtain the geographical location.  |

**Example**
S
shawn_he 已提交
1296

S
shawn_he 已提交
1297 1298
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1299
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
1300
  try {
S
shawn_he 已提交
1301
      let location = geoLocationManager.getLastLocation();
S
shawn_he 已提交
1302
  } catch (err) {
S
shawn_he 已提交
1303
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
  }
  ```


## geoLocationManager.isLocationEnabled

isLocationEnabled(): boolean

Checks whether the location service is enabled.

**System capability**: SystemCapability.Location.Location.Core

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | boolean  | boolean | NA | Result indicating whether the location service is enabled.|

**Error codes**

S
shawn_he 已提交
1324
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1325 1326 1327 1328 1329 1330 1331 1332 1333

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.  |

**Example**

  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1334
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
1335
  try {
S
shawn_he 已提交
1336
      let locationEnabled = geoLocationManager.isLocationEnabled();
S
shawn_he 已提交
1337
  } catch (err) {
S
shawn_he 已提交
1338
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348
  }
  ```


## geoLocationManager.enableLocation

enableLocation(callback: AsyncCallback&lt;void&gt;): void;

Enables the location service. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
1349
**System API**: This is a system API.
S
shawn_he 已提交
1350 1351 1352 1353 1354 1355 1356 1357 1358

**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS

**System capability**: SystemCapability.Location.Location.Core

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1359
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to receive the error message.|
S
shawn_he 已提交
1360 1361 1362

**Error codes**

S
shawn_he 已提交
1363
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1364 1365 1366 1367 1368 1369

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**Example**
S
shawn_he 已提交
1370

S
shawn_he 已提交
1371 1372
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1373
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
1374 1375 1376 1377 1378 1379 1380
  try {
      geoLocationManager.enableLocation((err, data) => {
          if (err) {
              console.log('enableLocation: err=' + JSON.stringify(err));
          }
      });
  } catch (err) {
S
shawn_he 已提交
1381
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
  }
  ```


## geoLocationManager.enableLocation

enableLocation(): Promise&lt;void&gt;

Enables the location service. This API uses a promise to return the result.

S
shawn_he 已提交
1392
**System API**: This is a system API.
S
shawn_he 已提交
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405

**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS

**System capability**: SystemCapability.Location.Location.Core

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;void&gt;  | void | NA | Promise used to return the error message.|

**Error codes**

S
shawn_he 已提交
1406
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1407 1408 1409 1410 1411 1412

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**Example**
S
shawn_he 已提交
1413

S
shawn_he 已提交
1414 1415
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1416
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
1417 1418 1419 1420
  try {
      geoLocationManager.enableLocation().then((result) => {
          console.log('promise, enableLocation succeed');
      })
S
shawn_he 已提交
1421
      .catch((error:number) => {
S
shawn_he 已提交
1422 1423 1424
          console.log('promise, enableLocation: error=' + JSON.stringify(error));
      });
  } catch (err) {
S
shawn_he 已提交
1425
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1426 1427 1428 1429 1430 1431 1432 1433 1434
  }
  ```

## geoLocationManager.disableLocation

disableLocation(): void;

Disables the location service.

S
shawn_he 已提交
1435
**System API**: This is a system API.
S
shawn_he 已提交
1436 1437 1438 1439 1440 1441 1442

**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS

**System capability**: SystemCapability.Location.Location.Core

**Error codes**

S
shawn_he 已提交
1443
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1444 1445 1446 1447 1448 1449

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**Example**
S
shawn_he 已提交
1450

S
shawn_he 已提交
1451 1452
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1453
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
1454 1455 1456
  try {
      geoLocationManager.disableLocation();
  } catch (err) {
S
shawn_he 已提交
1457
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1458 1459 1460 1461 1462 1463 1464 1465
  }
  ```


## geoLocationManager.getAddressesFromLocation

getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void

S
shawn_he 已提交
1466
Converts coordinates into geographic description through reverse geocoding. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
1467 1468 1469 1470 1471 1472 1473 1474

**System capability**: SystemCapability.Location.Location.Geocoder

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
S
shawn_he 已提交
1475
  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to receive the reverse geocoding result.|
S
shawn_he 已提交
1476 1477 1478

**Error codes**

S
shawn_he 已提交
1479
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1480 1481 1482 1483 1484 1485 1486

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.   |
|3301300 | Reverse geocoding query failed.   |

**Example**
S
shawn_he 已提交
1487

S
shawn_he 已提交
1488 1489
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1490 1491
  import BusinessError from "@ohos.base";
  let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
S
shawn_he 已提交
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
  try {
      geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
          if (err) {
              console.log('getAddressesFromLocation: err=' + JSON.stringify(err));
          }
          if (data) {
              console.log('getAddressesFromLocation: data=' + JSON.stringify(data));
          }
      });
  } catch (err) {
S
shawn_he 已提交
1502
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1503 1504 1505 1506 1507 1508 1509 1510
  }
  ```


## geoLocationManager.getAddressesFromLocation

getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;;

S
shawn_he 已提交
1511
Converts coordinates into geographic description through reverse geocoding. This API uses a promise to return the result. 
S
shawn_he 已提交
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528

**System capability**: SystemCapability.Location.Location.Geocoder

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt;  | Array&lt;[GeoAddress](#geoaddress)&gt; | NA | Promise used to return the reverse geocoding result.|

**Error codes**

S
shawn_he 已提交
1529
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1530 1531 1532 1533 1534 1535 1536

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.   |
|3301300 | Reverse geocoding query failed.   |

**Example**
S
shawn_he 已提交
1537

S
shawn_he 已提交
1538 1539
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1540 1541
  import BusinessError from "@ohos.base";
  let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
S
shawn_he 已提交
1542 1543 1544 1545
  try {
      geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
          console.log('getAddressesFromLocation: ' + JSON.stringify(data));
      })
S
shawn_he 已提交
1546
      .catch((error:number) => {
S
shawn_he 已提交
1547 1548 1549
          console.log('promise, getAddressesFromLocation: error=' + JSON.stringify(error));
      });
  } catch (err) {
S
shawn_he 已提交
1550
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1551 1552 1553 1554 1555 1556 1557 1558
  }
  ```


## geoLocationManager.getAddressesFromLocationName

getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void

S
shawn_he 已提交
1559
Converts geographic description into coordinates through geocoding. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
1560 1561 1562 1563 1564 1565 1566 1567

**System capability**: SystemCapability.Location.Location.Geocoder

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
S
shawn_he 已提交
1568
  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to receive the geocoding result.|
S
shawn_he 已提交
1569 1570 1571

**Error codes**

S
shawn_he 已提交
1572
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1573 1574 1575 1576 1577 1578 1579

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.   |
|3301400 | Geocoding query failed.   |

**Example**
S
shawn_he 已提交
1580

S
shawn_he 已提交
1581 1582
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1583 1584
  import BusinessError from "@ohos.base";
  let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
S
shawn_he 已提交
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594
  try {
      geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => {
          if (err) {
              console.log('getAddressesFromLocationName: err=' + JSON.stringify(err));
          }
          if (data) {
              console.log('getAddressesFromLocationName: data=' + JSON.stringify(data));
          }
      });
  } catch (err) {
S
shawn_he 已提交
1595
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1596 1597 1598 1599 1600 1601 1602 1603
  }
  ```


## geoLocationManager.getAddressesFromLocationName

getAddressesFromLocationName(request: GeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;

S
shawn_he 已提交
1604
Converts geographic description into coordinates through geocoding. This API uses a promise to return the result. 
S
shawn_he 已提交
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621

**System capability**: SystemCapability.Location.Location.Geocoder

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt;  | Array&lt;[GeoAddress](#geoaddress)&gt; | NA | Promise used to return the geocoding result.|

**Error codes**

S
shawn_he 已提交
1622
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1623 1624 1625 1626 1627 1628 1629

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.   |
|3301400 | Geocoding query failed.   |

**Example**
S
shawn_he 已提交
1630

S
shawn_he 已提交
1631 1632
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1633 1634
  import BusinessError from "@ohos.base";
  let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
S
shawn_he 已提交
1635 1636 1637 1638
  try {
      geoLocationManager.getAddressesFromLocationName(geocodeRequest).then((result) => {
          console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
      })
S
shawn_he 已提交
1639
      .catch((error:number) => {
S
shawn_he 已提交
1640 1641 1642
          console.log('promise, getAddressesFromLocationName: error=' + JSON.stringify(error));
      });
  } catch (err) {
S
shawn_he 已提交
1643
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
  }
  ```

## geoLocationManager.isGeocoderAvailable

isGeocoderAvailable(): boolean;

Obtains the (reverse) geocoding service status.

**System capability**: SystemCapability.Location.Location.Geocoder

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | boolean  | boolean | NA | Result indicating whether the (reverse) geocoding service is available.|

**Error codes**

S
shawn_he 已提交
1663
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1664 1665 1666 1667 1668 1669

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.   |

**Example**
S
shawn_he 已提交
1670

S
shawn_he 已提交
1671 1672
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1673
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
1674
  try {
S
shawn_he 已提交
1675
      let isAvailable = geoLocationManager.isGeocoderAvailable();
S
shawn_he 已提交
1676
  } catch (err) {
S
shawn_he 已提交
1677
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1678 1679 1680 1681 1682 1683 1684 1685 1686 1687
  }
  ```


## geoLocationManager.getCachedGnssLocationsSize

getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;): void;

Obtains the number of cached GNSS locations. 

S
shawn_he 已提交
1688
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1689 1690 1691 1692 1693 1694 1695

**System capability**: SystemCapability.Location.Location.Gnss

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1696
  | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to receive the number of cached GNSS locations. |
S
shawn_he 已提交
1697 1698 1699

**Error codes**

S
shawn_he 已提交
1700
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1701 1702 1703 1704 1705 1706 1707

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.   |
|3301100 | The location switch is off.   |

**Example**
S
shawn_he 已提交
1708

S
shawn_he 已提交
1709 1710
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1711
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
1712 1713 1714 1715 1716 1717 1718 1719 1720 1721
  try {
      geoLocationManager.getCachedGnssLocationsSize((err, size) => {
          if (err) {
              console.log('getCachedGnssLocationsSize: err=' + JSON.stringify(err));
          }
          if (size) {
              console.log('getCachedGnssLocationsSize: size=' + JSON.stringify(size));
          }
      });
  } catch (err) {
S
shawn_he 已提交
1722
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732
  }
  ```


## geoLocationManager.getCachedGnssLocationsSize

getCachedGnssLocationsSize(): Promise&lt;number&gt;;

Obtains the number of cached GNSS locations. 

S
shawn_he 已提交
1733
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744

**System capability**: SystemCapability.Location.Location.Gnss

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;number&gt;  | number | NA | Promise used to return the number of cached GNSS locations.|

**Error codes**

S
shawn_he 已提交
1745
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1746 1747 1748 1749 1750 1751 1752

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.   |
|3301100 | The location switch is off.   |

**Example**
S
shawn_he 已提交
1753

S
shawn_he 已提交
1754 1755
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1756
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
1757 1758 1759 1760
  try {
      geoLocationManager.getCachedGnssLocationsSize().then((result) => {
          console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
      }) 
S
shawn_he 已提交
1761
      .catch((error:number) => {
S
shawn_he 已提交
1762 1763 1764
          console.log('promise, getCachedGnssLocationsSize: error=' + JSON.stringify(error));
      });
  } catch (err) {
S
shawn_he 已提交
1765
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775
  }
  ```


## geoLocationManager.flushCachedGnssLocations

flushCachedGnssLocations(callback: AsyncCallback&lt;void&gt;): void;

Obtains all cached GNSS locations and clears the GNSS cache queue. 

S
shawn_he 已提交
1776
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1777 1778 1779 1780 1781 1782 1783

**System capability**: SystemCapability.Location.Location.Gnss

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1784
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to receive the error message.|
S
shawn_he 已提交
1785 1786 1787

**Error codes**

S
shawn_he 已提交
1788
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1789 1790 1791 1792 1793 1794 1795 1796

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.   |
|3301100 | The location switch is off.   |
|3301200 | Failed to obtain the geographical location.   |

**Example**
S
shawn_he 已提交
1797

S
shawn_he 已提交
1798 1799
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1800
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
1801 1802 1803 1804 1805 1806 1807
  try {
      geoLocationManager.flushCachedGnssLocations((err, result) => {
          if (err) {
              console.log('flushCachedGnssLocations: err=' + JSON.stringify(err));
          }
      });
  } catch (err) {
S
shawn_he 已提交
1808
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1809 1810
  }
  ```
S
shawn_he 已提交
1811 1812


S
shawn_he 已提交
1813
## geoLocationManager.flushCachedGnssLocations
S
shawn_he 已提交
1814

S
shawn_he 已提交
1815 1816 1817 1818
flushCachedGnssLocations(): Promise&lt;void&gt;;

Obtains all cached GNSS locations and clears the GNSS cache queue. 

S
shawn_he 已提交
1819
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1820 1821 1822 1823 1824 1825 1826

**System capability**: SystemCapability.Location.Location.Gnss

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1827
  | Promise&lt;void&gt;  | void | NA | Promise used to receive the error code.|
S
shawn_he 已提交
1828 1829 1830

**Error codes**

S
shawn_he 已提交
1831
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1832 1833 1834 1835 1836 1837 1838 1839

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.   |
|3301100 | The location switch is off.   |
|3301200 | Failed to obtain the geographical location.   |

**Example**
S
shawn_he 已提交
1840

S
shawn_he 已提交
1841 1842
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1843
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
1844 1845 1846 1847
  try {
      geoLocationManager.flushCachedGnssLocations().then((result) => {
          console.log('promise, flushCachedGnssLocations success');
      })
S
shawn_he 已提交
1848
      .catch((error:number) => {
S
shawn_he 已提交
1849 1850 1851
          console.log('promise, flushCachedGnssLocations: error=' + JSON.stringify(error));
      });
  } catch (err) {
S
shawn_he 已提交
1852
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1853 1854 1855 1856 1857 1858 1859 1860 1861
  }
  ```


## geoLocationManager.sendCommand

sendCommand(command: LocationCommand, callback: AsyncCallback&lt;void&gt;): void;

Sends an extended command to the location subsystem. 
S
shawn_he 已提交
1862 1863 1864

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
1865 1866 1867 1868 1869
**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | command |  [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
S
shawn_he 已提交
1870
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to receive the error code.|
S
shawn_he 已提交
1871 1872 1873

**Error codes**

S
shawn_he 已提交
1874
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1875 1876 1877 1878 1879 1880

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.   |

**Example**
S
shawn_he 已提交
1881

S
shawn_he 已提交
1882 1883
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1884 1885
  import BusinessError from "@ohos.base";
  let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
S
shawn_he 已提交
1886 1887 1888 1889 1890 1891 1892
  try {
      geoLocationManager.sendCommand(requestInfo, (err, result) => {
          if (err) {
              console.log('sendCommand: err=' + JSON.stringify(err));
          }
      });
  } catch (err) {
S
shawn_he 已提交
1893
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904
  }
  ```


## geoLocationManager.sendCommand

sendCommand(command: LocationCommand): Promise&lt;void&gt;;

Sends an extended command to the location subsystem. 

**System capability**: SystemCapability.Location.Location.Core
S
shawn_he 已提交
1905 1906 1907

**Parameters**

S
shawn_he 已提交
1908 1909 1910
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
S
shawn_he 已提交
1911 1912 1913

**Return value**

S
shawn_he 已提交
1914 1915
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1916
  | Promise&lt;void&gt;  | void | NA | Promise used to receive the error code.|
S
shawn_he 已提交
1917 1918 1919

**Error codes**

S
shawn_he 已提交
1920
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1921

S
shawn_he 已提交
1922 1923 1924
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
1925 1926

**Example**
S
shawn_he 已提交
1927

S
shawn_he 已提交
1928 1929
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1930 1931
  import BusinessError from "@ohos.base";
  let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
S
shawn_he 已提交
1932 1933 1934 1935
  try {
      geoLocationManager.sendCommand(requestInfo).then((result) => {
          console.log('promise, sendCommand success');
      })  
S
shawn_he 已提交
1936
      .catch((error:number) => {
S
shawn_he 已提交
1937 1938 1939
          console.log('promise, sendCommand: error=' + JSON.stringify(error));
      });
  } catch (err) {
S
shawn_he 已提交
1940
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1941
  }
S
shawn_he 已提交
1942 1943 1944
  ```


S
shawn_he 已提交
1945
## geoLocationManager.getCountryCode
S
shawn_he 已提交
1946

S
shawn_he 已提交
1947
getCountryCode(callback: AsyncCallback&lt;CountryCode&gt;): void;
S
shawn_he 已提交
1948

S
shawn_he 已提交
1949
Obtains the current country code.
S
shawn_he 已提交
1950 1951 1952 1953 1954

**System capability**: SystemCapability.Location.Location.Core

**Parameters**

S
shawn_he 已提交
1955 1956
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1957
  | callback | AsyncCallback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to receive the country code.|
S
shawn_he 已提交
1958 1959 1960

**Error codes**

S
shawn_he 已提交
1961
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1962

S
shawn_he 已提交
1963 1964 1965 1966
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301500 | Failed to query the area information.|
S
shawn_he 已提交
1967 1968

**Example**
S
shawn_he 已提交
1969

S
shawn_he 已提交
1970 1971
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1972
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
1973 1974 1975 1976 1977 1978 1979 1980 1981 1982
  try {
      geoLocationManager.getCountryCode((err, result) => {
          if (err) {
              console.log('getCountryCode: err=' + JSON.stringify(err));
          }
          if (result) {
              console.log('getCountryCode: result=' + JSON.stringify(result));
          }
      });
  } catch (err) {
S
shawn_he 已提交
1983
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999
  }
  ```


## geoLocationManager.getCountryCode

getCountryCode(): Promise&lt;CountryCode&gt;;

Obtains the current country code.

**System capability**: SystemCapability.Location.Location.Core

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
2000
  | Promise&lt;[CountryCode](#countrycode)&gt; | [CountryCode](#countrycode) | NA | Promise used to receive the country code.|
S
shawn_he 已提交
2001 2002

**Error codes**
S
shawn_he 已提交
2003

S
shawn_he 已提交
2004
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
2005 2006 2007 2008 2009 2010 2011

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301500 | Failed to query the area information.|

**Example**
S
shawn_he 已提交
2012

S
shawn_he 已提交
2013 2014
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2015
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
2016 2017 2018 2019 2020
  try {
      geoLocationManager.getCountryCode()
      .then((result) => {
          console.log('promise, getCountryCode: result=' + JSON.stringify(result));
      })
S
shawn_he 已提交
2021
      .catch((error:number) => {
S
shawn_he 已提交
2022 2023 2024
          console.log('promise, getCountryCode: error=' + JSON.stringify(error));
      });
  } catch (err) {
S
shawn_he 已提交
2025
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
2026
  }
S
shawn_he 已提交
2027 2028 2029
  ```


S
shawn_he 已提交
2030
## geoLocationManager.enableLocationMock
S
shawn_he 已提交
2031

S
shawn_he 已提交
2032
enableLocationMock(): void;
S
shawn_he 已提交
2033

S
shawn_he 已提交
2034
Enables the mock location function.
S
shawn_he 已提交
2035 2036 2037

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
2038
**System API**: This is a system API.
S
shawn_he 已提交
2039

S
shawn_he 已提交
2040 2041
**Error codes**

S
shawn_he 已提交
2042
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
2043 2044 2045 2046 2047 2048 2049

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.|

**Example**
S
shawn_he 已提交
2050

S
shawn_he 已提交
2051 2052
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2053
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
2054 2055 2056
  try {
      geoLocationManager.enableLocationMock();
  } catch (err) {
S
shawn_he 已提交
2057
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
2058 2059 2060 2061 2062 2063 2064
  }
  ```


## geoLocationManager.disableLocationMock

disableLocationMock(): void;
S
shawn_he 已提交
2065

S
shawn_he 已提交
2066 2067 2068 2069
Disables the mock location function.

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
2070
**System API**: This is a system API.
S
shawn_he 已提交
2071 2072 2073

**Error codes**

S
shawn_he 已提交
2074
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
2075

S
shawn_he 已提交
2076 2077 2078 2079
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.|
S
shawn_he 已提交
2080 2081

**Example**
S
shawn_he 已提交
2082

S
shawn_he 已提交
2083 2084
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2085
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
2086 2087 2088
  try {
      geoLocationManager.disableLocationMock();
  } catch (err) {
S
shawn_he 已提交
2089
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
2090
  }
S
shawn_he 已提交
2091 2092 2093
  ```


S
shawn_he 已提交
2094
## geoLocationManager.setMockedLocations
S
shawn_he 已提交
2095

S
shawn_he 已提交
2096
setMockedLocations(config: LocationMockConfig): void;
S
shawn_he 已提交
2097

S
shawn_he 已提交
2098
Sets the mock location information. The mock locations will be reported at the interval specified in this API.
S
shawn_he 已提交
2099

S
shawn_he 已提交
2100 2101
This API can be invoked only after [geoLocationManager.enableLocationMock](#geolocationmanagerenablelocationmock) is called.

S
shawn_he 已提交
2102 2103
**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
2104
**System API**: This is a system API.
S
shawn_he 已提交
2105 2106 2107

**Parameters**

S
shawn_he 已提交
2108 2109 2110
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | config |  [LocationMockConfig](#locationmockconfig) | Yes| Mock location information, including the interval for reporting the mock locations and the array of the mock locations.|
S
shawn_he 已提交
2111 2112 2113

**Error codes**

S
shawn_he 已提交
2114
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
2115

S
shawn_he 已提交
2116 2117 2118 2119
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.|
S
shawn_he 已提交
2120 2121

**Example**
S
shawn_he 已提交
2122

S
shawn_he 已提交
2123 2124
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2125 2126
  import BusinessError from "@ohos.base";
  let locations:Array<geoLocationManager.Location> = [
S
shawn_he 已提交
2127 2128 2129 2130 2131 2132
      {"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true},
      {"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true},
      {"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true},
      {"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true},
      {"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true}
  ];
S
shawn_he 已提交
2133
  let config:geoLocationManager.LocationMockConfig = {"timeInterval": 5, "locations": locations};
S
shawn_he 已提交
2134
  try {
S
shawn_he 已提交
2135
      geoLocationManager.enableLocationMock();
S
shawn_he 已提交
2136 2137
      geoLocationManager.setMockedLocations(config);
  } catch (err) {
S
shawn_he 已提交
2138
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
2139
  }
S
shawn_he 已提交
2140 2141 2142
  ```


S
shawn_he 已提交
2143
## geoLocationManager.enableReverseGeocodingMock
S
shawn_he 已提交
2144

S
shawn_he 已提交
2145
enableReverseGeocodingMock(): void;
S
shawn_he 已提交
2146

S
shawn_he 已提交
2147
Enables the mock reverse geocoding function.
S
shawn_he 已提交
2148 2149 2150

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
2151
**System API**: This is a system API.
S
shawn_he 已提交
2152

S
shawn_he 已提交
2153 2154
**Error codes**

S
shawn_he 已提交
2155
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
2156 2157 2158 2159 2160 2161

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**Example**
S
shawn_he 已提交
2162

S
shawn_he 已提交
2163 2164
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2165
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
2166 2167 2168
  try {
      geoLocationManager.enableReverseGeocodingMock();
  } catch (err) {
S
shawn_he 已提交
2169
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180
  }
  ```


## geoLocationManager.disableReverseGeocodingMock

disableReverseGeocodingMock(): void;

Disables the mock geocoding function.

**System capability**: SystemCapability.Location.Location.Core
S
shawn_he 已提交
2181

S
shawn_he 已提交
2182
**System API**: This is a system API.
S
shawn_he 已提交
2183 2184 2185

**Error codes**

S
shawn_he 已提交
2186
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
2187

S
shawn_he 已提交
2188 2189 2190
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
2191 2192

**Example**
S
shawn_he 已提交
2193

S
shawn_he 已提交
2194 2195
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2196
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
2197 2198 2199
  try {
      geoLocationManager.disableReverseGeocodingMock();
  } catch (err) {
S
shawn_he 已提交
2200
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
2201
  }
S
shawn_he 已提交
2202 2203 2204 2205 2206
  ```


## geoLocationManager.setReverseGeocodingMockInfo

S
shawn_he 已提交
2207
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;): void;
S
shawn_he 已提交
2208

S
shawn_he 已提交
2209
Sets 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.
S
shawn_he 已提交
2210

S
shawn_he 已提交
2211 2212
This API can be invoked only after [geoLocationManager.enableReverseGeocodingMock](#geolocationmanagerenablereversegeocodingmock) is called.

S
shawn_he 已提交
2213 2214
**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
2215
**System API**: This is a system API.
S
shawn_he 已提交
2216 2217 2218

**Parameters**

S
shawn_he 已提交
2219 2220
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
2221
  | mockInfos | Array&lt;[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)&gt; | Yes| Array of information of the mock reverse geocoding function, including a location and a geographical name.|
S
shawn_he 已提交
2222 2223 2224

**Error codes**

S
shawn_he 已提交
2225
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
2226

S
shawn_he 已提交
2227 2228 2229
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
2230 2231

**Example**
S
shawn_he 已提交
2232

S
shawn_he 已提交
2233 2234
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2235 2236 2237 2238 2239 2240 2241
  import BusinessError from "@ohos.base";
  let mockInfos:Array<geoLocationManager.ReverseGeocodingMockInfo> = [
      {"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "isFromMock": true}},
      {"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "isFromMock": true}},
      {"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "isFromMock": true}},
      {"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "isFromMock": true}},
      {"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "isFromMock": true}},
S
shawn_he 已提交
2242
  ];
S
shawn_he 已提交
2243
  try {
S
shawn_he 已提交
2244
      geoLocationManager.enableReverseGeocodingMock();
S
shawn_he 已提交
2245 2246
      geoLocationManager.setReverseGeocodingMockInfo(mockInfos);
  } catch (err) {
S
shawn_he 已提交
2247
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
2248
  }
S
shawn_he 已提交
2249 2250 2251
  ```


S
shawn_he 已提交
2252
## geoLocationManager.isLocationPrivacyConfirmed
S
shawn_he 已提交
2253

S
shawn_he 已提交
2254
isLocationPrivacyConfirmed(type: LocationPrivacyType): boolean;
S
shawn_he 已提交
2255

S
shawn_he 已提交
2256
Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications.
S
shawn_he 已提交
2257

S
shawn_he 已提交
2258
**System API**: This is a system API.
S
shawn_he 已提交
2259

S
shawn_he 已提交
2260 2261
**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
2262 2263
**Parameters**

S
shawn_he 已提交
2264 2265 2266
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | 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.|
S
shawn_he 已提交
2267 2268 2269

**Return value**

S
shawn_he 已提交
2270 2271
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
2272
  | boolean  | boolean | NA | Whether the user agrees with the privacy statement.|
S
shawn_he 已提交
2273 2274 2275

**Error codes**

S
shawn_he 已提交
2276
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
2277

S
shawn_he 已提交
2278 2279 2280
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
2281 2282

**Example**
S
shawn_he 已提交
2283

S
shawn_he 已提交
2284 2285
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2286
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
2287
  try {
S
shawn_he 已提交
2288
      let isConfirmed = geoLocationManager.isLocationPrivacyConfirmed(1);
S
shawn_he 已提交
2289
  } catch (err) {
S
shawn_he 已提交
2290
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
2291 2292 2293
  }
  ```

S
shawn_he 已提交
2294

S
shawn_he 已提交
2295 2296 2297 2298 2299 2300
## geoLocationManager.setLocationPrivacyConfirmStatus

setLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean): void;

Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications.

S
shawn_he 已提交
2301
**System API**: This is a system API.
S
shawn_he 已提交
2302 2303 2304 2305 2306 2307 2308 2309 2310 2311

**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS

**System capability**: SystemCapability.Location.Location.Core

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | 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.|
S
shawn_he 已提交
2312
  | isConfirmed | boolean | Yes| Whether the user agrees with the privacy statement.|
S
shawn_he 已提交
2313 2314 2315

**Error codes**

S
shawn_he 已提交
2316
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
2317 2318 2319 2320 2321 2322

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**Example**
S
shawn_he 已提交
2323

S
shawn_he 已提交
2324 2325
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2326
  import BusinessError from "@ohos.base";
S
shawn_he 已提交
2327 2328 2329
  try {
      geoLocationManager.setLocationPrivacyConfirmStatus(1, true);
  } catch (err) {
S
shawn_he 已提交
2330
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
2331
  }
S
shawn_he 已提交
2332
  ```
S
shawn_he 已提交
2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356


## geoLocationManager.getLocatingRequiredData<sup>10+</sup>

getLocatingRequiredData(config: LocatingRequiredDataConfig): Promise&lt;Array&lt;LocatingRequiredData&gt;&gt;;

Obtains the required data of the location service. This API uses a promise to return the result.

**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION

**System capability**: SystemCapability.Location.Location.Core

**System API**: This is a system API.

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.|

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
2357
  | Promise&lt;Array&lt;[LocatingRequiredData](#locatingrequireddata10)&gt;&gt;  | [LocatingRequiredData](#locatingrequireddata10) | NA | Promise used to receive the required data of the location service, such as the Wi-Fi and Bluetooth scanning information.|
S
shawn_he 已提交
2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370

**Error codes**

For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
|3301800  | Failed to start WiFi or Bluetooth scanning.                    |

**Example**

  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2371 2372
  import BusinessError from "@ohos.base";
  let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
S
shawn_he 已提交
2373 2374 2375 2376
  try {
      geoLocationManager.getLocatingRequiredData(config).then((result) => {
          console.log('getLocatingRequiredData return: ' + JSON.stringify(result));
      })  
S
shawn_he 已提交
2377
      .catch((error:number) => {
S
shawn_he 已提交
2378 2379 2380
          console.log('promise, getLocatingRequiredData: error=' + JSON.stringify(error));
      });
  } catch (err) {
S
shawn_he 已提交
2381
      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
S
shawn_he 已提交
2382 2383
  }
  ```