js-apis-geoLocationManager.md 89.0 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
  let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
S
shawn_he 已提交
430
  let locationChange = (location) => {
S
shawn_he 已提交
431 432
      console.log('locationChanger: data: ' + JSON.stringify(location));
  };
S
shawn_he 已提交
433
  try {
S
shawn_he 已提交
434
      geoLocationManager.on('locationChange', requestInfo, locationChange);
S
shawn_he 已提交
435 436 437
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
438
  
S
shawn_he 已提交
439 440 441
  ```


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

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

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

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

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

**Parameters**

S
shawn_he 已提交
454 455
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
456
  | type | string | Yes| Event type. The value **locationChange** indicates a location change.|
S
shawn_he 已提交
457
  | 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 已提交
458 459 460

**Error codes**

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

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

**Example**
S
shawn_he 已提交
470

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


S
shawn_he 已提交
486
## geoLocationManager.on('locationEnabledChange')
S
shawn_he 已提交
487

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

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

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

**Parameters**

S
shawn_he 已提交
496 497
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
498 499
  | 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 已提交
500 501 502

**Error codes**

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

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

**Example**
S
shawn_he 已提交
510

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


S
shawn_he 已提交
524
## geoLocationManager.off('locationEnabledChange')
S
shawn_he 已提交
525

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

S
shawn_he 已提交
528
Unsubscribes from location service status change events.
S
shawn_he 已提交
529 530 531

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

S
shawn_he 已提交
532
**Parameters**
S
shawn_he 已提交
533

S
shawn_he 已提交
534 535
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
536
  | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change.|
S
shawn_he 已提交
537
  | 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 已提交
538 539 540

**Error codes**

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

S
shawn_he 已提交
543 544 545
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
546 547

**Example**
S
shawn_he 已提交
548

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


S
shawn_he 已提交
563
## geoLocationManager.on('cachedGnssLocationsChange')
S
shawn_he 已提交
564

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

S
shawn_he 已提交
567
Subscribes to cached GNSS location reports.
S
shawn_he 已提交
568

S
shawn_he 已提交
569
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
570

S
shawn_he 已提交
571
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
572 573 574

**Parameters**

S
shawn_he 已提交
575 576 577 578
  | 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 已提交
579
  | callback | Callback&lt;boolean&gt; | Yes| Callback used to receive cached GNSS locations.|
S
shawn_he 已提交
580 581 582

**Error codes**

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

S
shawn_he 已提交
585 586 587 588 589
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
590 591

**Example**
S
shawn_he 已提交
592

S
shawn_he 已提交
593 594
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
595
  let cachedLocationsCb = (locations) => {
S
shawn_he 已提交
596 597
      console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
  }
S
shawn_he 已提交
598
  let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
S
shawn_he 已提交
599
  try {
S
shawn_he 已提交
600
      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
S
shawn_he 已提交
601 602 603 604 605 606
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


S
shawn_he 已提交
607
## geoLocationManager.off('cachedGnssLocationsChange')
S
shawn_he 已提交
608

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

S
shawn_he 已提交
611
Unsubscribes from cached GNSS location reports.
S
shawn_he 已提交
612

S
shawn_he 已提交
613
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
614

S
shawn_he 已提交
615
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
616

S
shawn_he 已提交
617
**Parameters**
S
shawn_he 已提交
618

S
shawn_he 已提交
619 620 621 622
  | 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 已提交
623 624 625

**Error codes**

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

S
shawn_he 已提交
628 629 630 631 632
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
633 634

**Example**
S
shawn_he 已提交
635

S
shawn_he 已提交
636 637
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
638
  let cachedLocationsCb = (locations) => {
S
shawn_he 已提交
639 640
      console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
  }
S
shawn_he 已提交
641
  let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
S
shawn_he 已提交
642 643 644 645 646 647
  try {
      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
      geoLocationManager.off('cachedGnssLocationsChange');
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
648 649 650
  ```


S
shawn_he 已提交
651
## geoLocationManager.on('satelliteStatusChange')
S
shawn_he 已提交
652

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

S
shawn_he 已提交
655
Subscribes to GNSS satellite status change events.
S
shawn_he 已提交
656

S
shawn_he 已提交
657
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
658

S
shawn_he 已提交
659
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
660 661 662

**Parameters**

S
shawn_he 已提交
663 664
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
665 666
  | 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 已提交
667 668 669

**Error codes**

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

S
shawn_he 已提交
672 673 674 675
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
676 677

**Example**
S
shawn_he 已提交
678

S
shawn_he 已提交
679 680
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
681
  let gnssStatusCb = (satelliteStatusInfo) => {
S
shawn_he 已提交
682 683 684 685 686 687 688 689
      console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
  }

  try {
      geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
690 691 692
  ```


S
shawn_he 已提交
693
## geoLocationManager.off('satelliteStatusChange')
S
shawn_he 已提交
694

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

S
shawn_he 已提交
697
Unsubscribes from GNSS satellite status change events.
S
shawn_he 已提交
698

S
shawn_he 已提交
699
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
700

S
shawn_he 已提交
701
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
702 703 704

**Parameters**

S
shawn_he 已提交
705 706
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
707
  | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change.|
S
shawn_he 已提交
708
  | 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 已提交
709 710 711

**Error codes**

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

S
shawn_he 已提交
714 715 716 717
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
718 719


S
shawn_he 已提交
720
**Example**
S
shawn_he 已提交
721

S
shawn_he 已提交
722 723
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
724
  let gnssStatusCb = (satelliteStatusInfo) => {
S
shawn_he 已提交
725 726 727 728 729 730 731 732
      console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
  }
  try {
      geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
      geoLocationManager.off('satelliteStatusChange', gnssStatusCb);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
733 734 735
  ```


S
shawn_he 已提交
736
## geoLocationManager.on('nmeaMessage')
S
shawn_he 已提交
737

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

S
shawn_he 已提交
740
Subscribes to GNSS NMEA message change events.
S
shawn_he 已提交
741

S
shawn_he 已提交
742
**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
743

S
shawn_he 已提交
744
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
745 746 747

**Parameters**

S
shawn_he 已提交
748 749
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
750 751
  | 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 已提交
752 753 754

**Error codes**

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

S
shawn_he 已提交
757 758 759 760
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
761 762


S
shawn_he 已提交
763
**Example**
S
shawn_he 已提交
764

S
shawn_he 已提交
765 766
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
767
  let nmeaCb = (str) => {
S
shawn_he 已提交
768 769
      console.log('nmeaMessage: ' + JSON.stringify(str));
  }
S
shawn_he 已提交
770

S
shawn_he 已提交
771 772 773 774 775 776
  try {
      geoLocationManager.on('nmeaMessage', nmeaCb );
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```
S
shawn_he 已提交
777 778


S
shawn_he 已提交
779
## geoLocationManager.off('nmeaMessage')
S
shawn_he 已提交
780

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

S
shawn_he 已提交
783
Unsubscribes from GNSS NMEA message change events.
S
shawn_he 已提交
784

S
shawn_he 已提交
785
**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
786

S
shawn_he 已提交
787
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
788 789 790

**Parameters**

S
shawn_he 已提交
791 792
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
793
  | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change.|
S
shawn_he 已提交
794
  | 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 已提交
795 796 797

**Error codes**

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

S
shawn_he 已提交
800 801 802 803
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
804 805


S
shawn_he 已提交
806
**Example**
S
shawn_he 已提交
807

S
shawn_he 已提交
808 809
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
810
  let nmeaCb = (str) => {
S
shawn_he 已提交
811 812 813 814 815 816 817 818 819
      console.log('nmeaMessage: ' + JSON.stringify(str));
  }

  try {
      geoLocationManager.on('nmeaMessage', nmeaCb);
      geoLocationManager.off('nmeaMessage', nmeaCb);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
820 821 822
  ```


S
shawn_he 已提交
823
## geoLocationManager.on('gnssFenceStatusChange')
S
shawn_he 已提交
824

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

S
shawn_he 已提交
827
Subscribes to status change events of the specified geofence.
S
shawn_he 已提交
828

S
shawn_he 已提交
829
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
830 831

**System capability**: SystemCapability.Location.Location.Geofence
S
shawn_he 已提交
832 833 834

**Parameters**

S
shawn_he 已提交
835 836
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
837
  | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.|
S
shawn_he 已提交
838
  | request |  [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
S
shawn_he 已提交
839
  | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
S
shawn_he 已提交
840 841 842

**Error codes**

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

S
shawn_he 已提交
845 846 847 848 849
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301600 | Failed to operate the geofence.                                     |
S
shawn_he 已提交
850 851

**Example**
S
shawn_he 已提交
852

S
shawn_he 已提交
853 854
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
855
  import wantAgent from '@ohos.app.ability.wantAgent';
S
shawn_he 已提交
856 857 858 859 860
  
  let wantAgentInfo = {
      wants: [
          {
              bundleName: "com.example.myapplication",
S
shawn_he 已提交
861
              abilityName: "EntryAbility",
S
shawn_he 已提交
862
              action: "action1"
S
shawn_he 已提交
863 864 865 866
          }
      ],
      operationType: wantAgent.OperationType.START_ABILITY,
      requestCode: 0,
S
shawn_he 已提交
867
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
S
shawn_he 已提交
868 869 870
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
S
shawn_he 已提交
871
    let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
S
shawn_he 已提交
872 873 874 875 876
    try {
        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
    } catch (err) {
        console.error("errCode:" + err.code + ",errMessage:" + err.message);
    }
S
shawn_he 已提交
877 878 879 880
  });
  ```


S
shawn_he 已提交
881
## geoLocationManager.off('gnssFenceStatusChange')
S
shawn_he 已提交
882

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

S
shawn_he 已提交
885
Unsubscribes from status change events of the specified geofence.
S
shawn_he 已提交
886

S
shawn_he 已提交
887
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
888

S
shawn_he 已提交
889 890 891
**System capability**: SystemCapability.Location.Location.Geofence

**Parameters**
S
shawn_he 已提交
892

S
shawn_he 已提交
893 894
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
895
  | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.|
S
shawn_he 已提交
896
  | request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
S
shawn_he 已提交
897
  | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
S
shawn_he 已提交
898 899 900

**Error codes**

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

S
shawn_he 已提交
903 904 905 906 907
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301600 | Failed to operate the geofence.                                     |
S
shawn_he 已提交
908 909

**Example**
S
shawn_he 已提交
910

S
shawn_he 已提交
911 912
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
913
  import wantAgent from '@ohos.app.ability.wantAgent';
S
shawn_he 已提交
914 915 916 917 918
  
  let wantAgentInfo = {
      wants: [
          {
              bundleName: "com.example.myapplication",
S
shawn_he 已提交
919
              abilityName: "EntryAbility",
S
shawn_he 已提交
920
              action: "action1",
S
shawn_he 已提交
921 922 923 924 925 926 927 928
          }
      ],
      operationType: wantAgent.OperationType.START_ABILITY,
      requestCode: 0,
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
S
shawn_he 已提交
929
    let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
S
shawn_he 已提交
930 931 932 933 934 935
    try {
        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
        geoLocationManager.off('gnssFenceStatusChange', requestInfo, wantAgentObj);
    } catch (err) {
        console.error("errCode:" + err.code + ",errMessage:" + err.message);
    }
S
shawn_he 已提交
936 937 938 939
  });
  ```


S
shawn_he 已提交
940
## geoLocationManager.on('countryCodeChange')
S
shawn_he 已提交
941

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

S
shawn_he 已提交
944
Subscribes to country code change events.
S
shawn_he 已提交
945 946 947 948 949

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

**Parameters**

S
shawn_he 已提交
950 951
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
952 953
  | 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 已提交
954 955 956

**Error codes**

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

S
shawn_he 已提交
959 960 961 962
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301500 | Failed to query the area information.                                       |
S
shawn_he 已提交
963 964


S
shawn_he 已提交
965
**Example**
S
shawn_he 已提交
966

S
shawn_he 已提交
967 968
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
969
  let callback = (code) => {
S
shawn_he 已提交
970 971 972 973 974 975 976 977
      console.log('countryCodeChange: ' + JSON.stringify(code));
  }

  try {
      geoLocationManager.on('countryCodeChange', callback);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
978 979 980
  ```


S
shawn_he 已提交
981 982 983
## geoLocationManager.off('countryCodeChange')

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

S
shawn_he 已提交
985
Unsubscribes from country code change events.
S
shawn_he 已提交
986 987 988

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

S
shawn_he 已提交
989
**Parameters**
S
shawn_he 已提交
990

S
shawn_he 已提交
991 992
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
993
  | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change.|
S
shawn_he 已提交
994
  | 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 已提交
995 996 997

**Error codes**

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

S
shawn_he 已提交
1000 1001 1002 1003
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301500 | Failed to query the area information.                                       |
S
shawn_he 已提交
1004 1005

**Example**
S
shawn_he 已提交
1006

S
shawn_he 已提交
1007 1008
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1009
  let callback = (code) => {
S
shawn_he 已提交
1010 1011 1012 1013 1014 1015 1016 1017 1018
      console.log('countryCodeChange: ' + JSON.stringify(code));
  }

  try {
      geoLocationManager.on('countryCodeChange', callback);
      geoLocationManager.off('countryCodeChange', callback);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1019 1020 1021
  ```


S
shawn_he 已提交
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 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 1068 1069 1070 1071 1072 1073 1074 1075 1076 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
## 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';
  let callback = (code) => {
      console.log('locatingRequiredDataChange: ' + JSON.stringify(code));
  }
  let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
  try {
      geoLocationManager.on('locatingRequiredDataChange', config, callback);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## 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';
  let callback = (code) => {
      console.log('locatingRequiredDataChange: ' + JSON.stringify(code));
  }
  let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
  try {
      geoLocationManager.on('locatingRequiredDataChange', config, callback);
      geoLocationManager.off('locatingRequiredDataChange', callback);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

S
shawn_he 已提交
1105

S
shawn_he 已提交
1106
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
1107

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

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

S
shawn_he 已提交
1112
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1113 1114

**System capability**: SystemCapability.Location.Location.Core
S
shawn_he 已提交
1115 1116 1117

**Parameters**

S
shawn_he 已提交
1118 1119 1120
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [CurrentLocationRequest](#currentlocationrequest) | Yes| Location request.|
S
shawn_he 已提交
1121
  | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to receive the current location.|
S
shawn_he 已提交
1122 1123 1124

**Error codes**

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

S
shawn_he 已提交
1127 1128 1129 1130 1131
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
1132 1133

**Example**
S
shawn_he 已提交
1134

S
shawn_he 已提交
1135 1136
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1137
  let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
S
shawn_he 已提交
1138
  let locationChange = (err, location) => {
S
shawn_he 已提交
1139
      if (err) {
S
shawn_he 已提交
1140
          console.log('locationChanger: err=' + JSON.stringify(err));
S
shawn_he 已提交
1141
      }
S
shawn_he 已提交
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
      if (location) {
          console.log('locationChanger: location=' + JSON.stringify(location));
      }
  };

  try {
      geoLocationManager.getCurrentLocation(requestInfo, locationChange);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1152 1153
  ```

S
shawn_he 已提交
1154
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
1155

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

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

S
shawn_he 已提交
1160
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1161 1162 1163

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

S
shawn_he 已提交
1164
**Parameters**
S
shawn_he 已提交
1165

S
shawn_he 已提交
1166 1167
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1168
  | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to receive the current location.|
S
shawn_he 已提交
1169 1170 1171

**Error codes**

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

S
shawn_he 已提交
1174 1175 1176 1177 1178
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
1179 1180

**Example**
S
shawn_he 已提交
1181

S
shawn_he 已提交
1182 1183
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1184
  let locationChange = (err, location) => {
S
shawn_he 已提交
1185 1186
      if (err) {
          console.log('locationChanger: err=' + JSON.stringify(err));
S
shawn_he 已提交
1187
      }
S
shawn_he 已提交
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197
      if (location) {
          console.log('locationChanger: location=' + JSON.stringify(location));
      }
  };

  try {
      geoLocationManager.getCurrentLocation(locationChange);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1198 1199
  ```

S
shawn_he 已提交
1200
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
1201

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

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

S
shawn_he 已提交
1206
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1207 1208 1209 1210 1211

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

**Parameters**

S
shawn_he 已提交
1212 1213 1214 1215 1216 1217 1218 1219 1220
  | 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 已提交
1221 1222 1223

**Error codes**

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

S
shawn_he 已提交
1226 1227 1228 1229 1230
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
1231 1232

**Example**
S
shawn_he 已提交
1233

S
shawn_he 已提交
1234 1235
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1236
  let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
S
shawn_he 已提交
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
  try {
      geoLocationManager.getCurrentLocation(requestInfo).then((result) => {
          console.log('current location: ' + JSON.stringify(result));
      })  
      .catch((error) => {
          console.log('promise, getCurrentLocation: error=' + JSON.stringify(error));
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.getLastLocation

getLastLocation(): Location

Obtains the last location.

S
shawn_he 已提交
1256
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267

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

**Return value**

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

**Error codes**

S
shawn_he 已提交
1268
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1269 1270 1271 1272 1273 1274 1275 1276

| 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 已提交
1277

S
shawn_he 已提交
1278 1279 1280
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
S
shawn_he 已提交
1281
      let location = geoLocationManager.getLastLocation();
S
shawn_he 已提交
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## 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 已提交
1304
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314

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

**Example**

  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
S
shawn_he 已提交
1315
      let locationEnabled = geoLocationManager.isLocationEnabled();
S
shawn_he 已提交
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## 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 已提交
1328
**System API**: This is a system API.
S
shawn_he 已提交
1329 1330 1331 1332 1333 1334 1335 1336 1337

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

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1338
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to receive the error message.|
S
shawn_he 已提交
1339 1340 1341

**Error codes**

S
shawn_he 已提交
1342
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1343 1344 1345 1346 1347 1348

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

**Example**
S
shawn_he 已提交
1349

S
shawn_he 已提交
1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      geoLocationManager.enableLocation((err, data) => {
          if (err) {
              console.log('enableLocation: err=' + JSON.stringify(err));
          }
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.enableLocation

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

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

S
shawn_he 已提交
1370
**System API**: This is a system API.
S
shawn_he 已提交
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383

**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 已提交
1384
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1385 1386 1387 1388 1389 1390

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

**Example**
S
shawn_he 已提交
1391

S
shawn_he 已提交
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      geoLocationManager.enableLocation().then((result) => {
          console.log('promise, enableLocation succeed');
      })
      .catch((error) => {
          console.log('promise, enableLocation: error=' + JSON.stringify(error));
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

## geoLocationManager.disableLocation

disableLocation(): void;

Disables the location service.

S
shawn_he 已提交
1412
**System API**: This is a system API.
S
shawn_he 已提交
1413 1414 1415 1416 1417 1418 1419

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

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

**Error codes**

S
shawn_he 已提交
1420
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1421 1422 1423 1424 1425 1426

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

**Example**
S
shawn_he 已提交
1427

S
shawn_he 已提交
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      geoLocationManager.disableLocation();
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.getAddressesFromLocation

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

S
shawn_he 已提交
1442
Converts coordinates into geographic description through reverse geocoding. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
1443 1444 1445 1446 1447 1448 1449 1450

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

**Parameters**

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

**Error codes**

S
shawn_he 已提交
1455
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1456 1457 1458 1459 1460 1461 1462

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

**Example**
S
shawn_he 已提交
1463

S
shawn_he 已提交
1464 1465
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1466
  let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
S
shawn_he 已提交
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485
  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) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.getAddressesFromLocation

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

S
shawn_he 已提交
1486
Converts coordinates into geographic description through reverse geocoding. This API uses a promise to return the result. 
S
shawn_he 已提交
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503

**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 已提交
1504
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1505 1506 1507 1508 1509 1510 1511

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

**Example**
S
shawn_he 已提交
1512

S
shawn_he 已提交
1513 1514
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1515
  let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
S
shawn_he 已提交
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532
  try {
      geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
          console.log('getAddressesFromLocation: ' + JSON.stringify(data));
      })
      .catch((error) => {
          console.log('promise, getAddressesFromLocation: error=' + JSON.stringify(error));
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.getAddressesFromLocationName

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

S
shawn_he 已提交
1533
Converts geographic description into coordinates through geocoding. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
1534 1535 1536 1537 1538 1539 1540 1541

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

**Parameters**

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

**Error codes**

S
shawn_he 已提交
1546
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1547 1548 1549 1550 1551 1552 1553

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

**Example**
S
shawn_he 已提交
1554

S
shawn_he 已提交
1555 1556
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1557
  let geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
S
shawn_he 已提交
1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576
  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) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.getAddressesFromLocationName

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

S
shawn_he 已提交
1577
Converts geographic description into coordinates through geocoding. This API uses a promise to return the result. 
S
shawn_he 已提交
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594

**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 已提交
1595
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1596 1597 1598 1599 1600 1601 1602

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

**Example**
S
shawn_he 已提交
1603

S
shawn_he 已提交
1604 1605
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1606
  let geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
S
shawn_he 已提交
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634
  try {
      geoLocationManager.getAddressesFromLocationName(geocodeRequest).then((result) => {
          console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
      })
      .catch((error) => {
          console.log('promise, getAddressesFromLocationName: error=' + JSON.stringify(error));
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

## 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 已提交
1635
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1636 1637 1638 1639 1640 1641

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

**Example**
S
shawn_he 已提交
1642

S
shawn_he 已提交
1643 1644 1645
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
S
shawn_he 已提交
1646
      let isAvailable = geoLocationManager.isGeocoderAvailable();
S
shawn_he 已提交
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.getCachedGnssLocationsSize

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

Obtains the number of cached GNSS locations. 

S
shawn_he 已提交
1659
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1660 1661 1662 1663 1664 1665 1666

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1667
  | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to receive the number of cached GNSS locations. |
S
shawn_he 已提交
1668 1669 1670

**Error codes**

S
shawn_he 已提交
1671
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1672 1673 1674 1675 1676 1677 1678

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

**Example**
S
shawn_he 已提交
1679

S
shawn_he 已提交
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  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) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.getCachedGnssLocationsSize

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

Obtains the number of cached GNSS locations. 

S
shawn_he 已提交
1703
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714

**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 已提交
1715
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1716 1717 1718 1719 1720 1721 1722

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

**Example**
S
shawn_he 已提交
1723

S
shawn_he 已提交
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      geoLocationManager.getCachedGnssLocationsSize().then((result) => {
          console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
      }) 
      .catch((error) => {
          console.log('promise, getCachedGnssLocationsSize: error=' + JSON.stringify(error));
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.flushCachedGnssLocations

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

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

S
shawn_he 已提交
1745
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1746 1747 1748 1749 1750 1751 1752

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1753
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to receive the error message.|
S
shawn_he 已提交
1754 1755 1756

**Error codes**

S
shawn_he 已提交
1757
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1758 1759 1760 1761 1762 1763 1764 1765

| 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 已提交
1766

S
shawn_he 已提交
1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      geoLocationManager.flushCachedGnssLocations((err, result) => {
          if (err) {
              console.log('flushCachedGnssLocations: err=' + JSON.stringify(err));
          }
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```
S
shawn_he 已提交
1779 1780


S
shawn_he 已提交
1781
## geoLocationManager.flushCachedGnssLocations
S
shawn_he 已提交
1782

S
shawn_he 已提交
1783 1784 1785 1786
flushCachedGnssLocations(): Promise&lt;void&gt;;

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

S
shawn_he 已提交
1787
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1788 1789 1790 1791 1792 1793 1794

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

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1795
  | Promise&lt;void&gt;  | void | NA | Promise used to receive the error code.|
S
shawn_he 已提交
1796 1797 1798

**Error codes**

S
shawn_he 已提交
1799
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1800 1801 1802 1803 1804 1805 1806 1807

| 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 已提交
1808

S
shawn_he 已提交
1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      geoLocationManager.flushCachedGnssLocations().then((result) => {
          console.log('promise, flushCachedGnssLocations success');
      })
      .catch((error) => {
          console.log('promise, flushCachedGnssLocations: error=' + JSON.stringify(error));
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.sendCommand

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

Sends an extended command to the location subsystem. 
S
shawn_he 已提交
1829 1830 1831

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

S
shawn_he 已提交
1832 1833 1834 1835 1836
**Parameters**

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

**Error codes**

S
shawn_he 已提交
1841
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1842 1843 1844 1845 1846 1847

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

**Example**
S
shawn_he 已提交
1848

S
shawn_he 已提交
1849 1850
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1851
  let requestInfo = {'scenario': 0x301, 'command': "command_1"};
S
shawn_he 已提交
1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870
  try {
      geoLocationManager.sendCommand(requestInfo, (err, result) => {
          if (err) {
              console.log('sendCommand: err=' + JSON.stringify(err));
          }
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## 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 已提交
1871 1872 1873

**Parameters**

S
shawn_he 已提交
1874 1875 1876
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
S
shawn_he 已提交
1877 1878 1879

**Return value**

S
shawn_he 已提交
1880 1881
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1882
  | Promise&lt;void&gt;  | void | NA | Promise used to receive the error code.|
S
shawn_he 已提交
1883 1884 1885

**Error codes**

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

S
shawn_he 已提交
1888 1889 1890
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
1891 1892

**Example**
S
shawn_he 已提交
1893

S
shawn_he 已提交
1894 1895
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1896
  let requestInfo = {'scenario': 0x301, 'command': "command_1"};
S
shawn_he 已提交
1897 1898 1899 1900 1901 1902 1903 1904 1905 1906
  try {
      geoLocationManager.sendCommand(requestInfo).then((result) => {
          console.log('promise, sendCommand success');
      })  
      .catch((error) => {
          console.log('promise, sendCommand: error=' + JSON.stringify(error));
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1907 1908 1909
  ```


S
shawn_he 已提交
1910
## geoLocationManager.getCountryCode
S
shawn_he 已提交
1911

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

S
shawn_he 已提交
1914
Obtains the current country code.
S
shawn_he 已提交
1915 1916 1917 1918 1919

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

**Parameters**

S
shawn_he 已提交
1920 1921
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1922
  | callback | AsyncCallback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to receive the country code.|
S
shawn_he 已提交
1923 1924 1925

**Error codes**

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

S
shawn_he 已提交
1928 1929 1930 1931
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301500 | Failed to query the area information.|
S
shawn_he 已提交
1932 1933

**Example**
S
shawn_he 已提交
1934

S
shawn_he 已提交
1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  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) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## 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 已提交
1964
  | Promise&lt;[CountryCode](#countrycode)&gt; | [CountryCode](#countrycode) | NA | Promise used to receive the country code.|
S
shawn_he 已提交
1965 1966

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

S
shawn_he 已提交
1968
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1969 1970 1971 1972 1973 1974 1975

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

**Example**
S
shawn_he 已提交
1976

S
shawn_he 已提交
1977 1978
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989
  try {
      geoLocationManager.getCountryCode()
      .then((result) => {
          console.log('promise, getCountryCode: result=' + JSON.stringify(result));
      })
      .catch((error) => {
          console.log('promise, getCountryCode: error=' + JSON.stringify(error));
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1990 1991 1992
  ```


S
shawn_he 已提交
1993
## geoLocationManager.enableLocationMock
S
shawn_he 已提交
1994

S
shawn_he 已提交
1995
enableLocationMock(): void;
S
shawn_he 已提交
1996

S
shawn_he 已提交
1997
Enables the mock location function.
S
shawn_he 已提交
1998 1999 2000

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

S
shawn_he 已提交
2001
**System API**: This is a system API.
S
shawn_he 已提交
2002

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

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

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

**Example**
S
shawn_he 已提交
2013

S
shawn_he 已提交
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      geoLocationManager.enableLocationMock();
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.disableLocationMock

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

S
shawn_he 已提交
2028 2029 2030 2031
Disables the mock location function.

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

S
shawn_he 已提交
2032
**System API**: This is a system API.
S
shawn_he 已提交
2033 2034 2035

**Error codes**

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

S
shawn_he 已提交
2038 2039 2040 2041
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.|
S
shawn_he 已提交
2042 2043

**Example**
S
shawn_he 已提交
2044

S
shawn_he 已提交
2045 2046
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2047 2048 2049 2050 2051
  try {
      geoLocationManager.disableLocationMock();
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
2052 2053 2054
  ```


S
shawn_he 已提交
2055
## geoLocationManager.setMockedLocations
S
shawn_he 已提交
2056

S
shawn_he 已提交
2057
setMockedLocations(config: LocationMockConfig): void;
S
shawn_he 已提交
2058

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

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

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

S
shawn_he 已提交
2065
**System API**: This is a system API.
S
shawn_he 已提交
2066 2067 2068

**Parameters**

S
shawn_he 已提交
2069 2070 2071
  | 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 已提交
2072 2073 2074

**Error codes**

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

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

**Example**
S
shawn_he 已提交
2083

S
shawn_he 已提交
2084 2085
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2086
  let locations = [
S
shawn_he 已提交
2087 2088 2089 2090 2091 2092
      {"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 已提交
2093
  let config = {"timeInterval": 5, "locations": locations};
S
shawn_he 已提交
2094
  try {
S
shawn_he 已提交
2095
      geoLocationManager.enableLocationMock();
S
shawn_he 已提交
2096 2097 2098 2099
      geoLocationManager.setMockedLocations(config);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
2100 2101 2102
  ```


S
shawn_he 已提交
2103
## geoLocationManager.enableReverseGeocodingMock
S
shawn_he 已提交
2104

S
shawn_he 已提交
2105
enableReverseGeocodingMock(): void;
S
shawn_he 已提交
2106

S
shawn_he 已提交
2107
Enables the mock reverse geocoding function.
S
shawn_he 已提交
2108 2109 2110

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

S
shawn_he 已提交
2111
**System API**: This is a system API.
S
shawn_he 已提交
2112

S
shawn_he 已提交
2113 2114
**Error codes**

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

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

**Example**
S
shawn_he 已提交
2122

S
shawn_he 已提交
2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      geoLocationManager.enableReverseGeocodingMock();
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.disableReverseGeocodingMock

disableReverseGeocodingMock(): void;

Disables the mock geocoding function.

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

S
shawn_he 已提交
2141
**System API**: This is a system API.
S
shawn_he 已提交
2142 2143 2144

**Error codes**

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

S
shawn_he 已提交
2147 2148 2149
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
2150 2151

**Example**
S
shawn_he 已提交
2152

S
shawn_he 已提交
2153 2154
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2155 2156 2157 2158 2159
  try {
      geoLocationManager.disableReverseGeocodingMock();
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
2160 2161 2162 2163 2164
  ```


## geoLocationManager.setReverseGeocodingMockInfo

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

S
shawn_he 已提交
2167
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 已提交
2168

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

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

S
shawn_he 已提交
2173
**System API**: This is a system API.
S
shawn_he 已提交
2174 2175 2176

**Parameters**

S
shawn_he 已提交
2177 2178
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
2179
  | 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 已提交
2180 2181 2182

**Error codes**

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

S
shawn_he 已提交
2185 2186 2187
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
2188 2189

**Example**
S
shawn_he 已提交
2190

S
shawn_he 已提交
2191 2192
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2193
  let mockInfos = [
S
shawn_he 已提交
2194 2195 2196 2197 2198 2199
      {"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
      {"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
      {"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
      {"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
      {"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
  ];
S
shawn_he 已提交
2200
  try {
S
shawn_he 已提交
2201
      geoLocationManager.enableReverseGeocodingMock();
S
shawn_he 已提交
2202 2203 2204 2205
      geoLocationManager.setReverseGeocodingMockInfo(mockInfos);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
2206 2207 2208
  ```


S
shawn_he 已提交
2209
## geoLocationManager.isLocationPrivacyConfirmed
S
shawn_he 已提交
2210

S
shawn_he 已提交
2211
isLocationPrivacyConfirmed(type: LocationPrivacyType): boolean;
S
shawn_he 已提交
2212

S
shawn_he 已提交
2213
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 已提交
2214

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

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

S
shawn_he 已提交
2219 2220
**Parameters**

S
shawn_he 已提交
2221 2222 2223
  | 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 已提交
2224 2225 2226

**Return value**

S
shawn_he 已提交
2227 2228
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
2229
  | boolean  | boolean | NA | Whether the user agrees with the privacy statement.|
S
shawn_he 已提交
2230 2231 2232

**Error codes**

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

S
shawn_he 已提交
2235 2236 2237
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
2238 2239

**Example**
S
shawn_he 已提交
2240

S
shawn_he 已提交
2241 2242 2243
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
S
shawn_he 已提交
2244
      let isConfirmed = geoLocationManager.isLocationPrivacyConfirmed(1);
S
shawn_he 已提交
2245 2246 2247 2248 2249
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

S
shawn_he 已提交
2250

S
shawn_he 已提交
2251 2252 2253 2254 2255 2256
## 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 已提交
2257
**System API**: This is a system API.
S
shawn_he 已提交
2258 2259 2260 2261 2262 2263 2264 2265 2266 2267

**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 已提交
2268
  | isConfirmed | boolean | Yes| Whether the user agrees with the privacy statement.|
S
shawn_he 已提交
2269 2270 2271

**Error codes**

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

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

**Example**
S
shawn_he 已提交
2279

S
shawn_he 已提交
2280 2281
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2282 2283 2284 2285 2286
  try {
      geoLocationManager.setLocationPrivacyConfirmStatus(1, true);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
2287
  ```
S
shawn_he 已提交
2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311


## 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 已提交
2312
  | 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 已提交
2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337

**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';
  let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
  try {
      geoLocationManager.getLocatingRequiredData(config).then((result) => {
          console.log('getLocatingRequiredData return: ' + JSON.stringify(result));
      })  
      .catch((error) => {
          console.log('promise, getLocatingRequiredData: error=' + JSON.stringify(error));
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```