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

S
shawn_he 已提交
3
The **geoLocationManager** module provides a wide array of location services, including GNSS positioning, network positioning, geocoding, reverse geocoding, and geofencing.
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 | Successful| Location accurate to meters.|
| 9 and later| ohos.permission.LOCATION | Failed| No location obtained.|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Successful| Location accurate to 5 kilometers.|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Successful| 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 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
## 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**.|
| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The value must be greater than or equal to **0**. A value smaller than **10** is recommended.|


## 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**.|
| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
| 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.|
| descriptionsSize | number | Yes| No| Total number of additional descriptions. The value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
| isFromMock | Boolean | Yes| No| Whether the geographic address is obtained from the mock reverse geocoding function.<br>**System API**: This is a system API.|


## LocationRequest

Defines a location request.

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

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request. For details about the value range, see [LocationRequestPriority](#locationrequestpriority).|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request. For details about the value range, see [LocationRequestScenario](#locationrequestscenario).|
| timeInterval | number | Yes| Yes| Time interval at which location information is reported, in seconds. The value must be greater than **0**.|
| distanceInterval | number | Yes| Yes| Distance interval at which location information is reported. The value must be greater than **0**, in meters.|
| maxAccuracy | number | Yes| Yes| Location accuracy. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled. The value must be greater than **0**.|


## CurrentLocationRequest

Defines the current location request.

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

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request. For details about the value range, see [LocationRequestPriority](#locationrequestpriority).|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request. 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 value must be greater than **0**.|
| timeoutMs | number | Yes| Yes| Timeout duration, in milliseconds. The minimum value is **1000**. The value must be greater than or equal to **1000**.|


## SatelliteStatusInfo

Defines the satellite status information.

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

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| satellitesNumber | number | Yes| No| Number of satellites. The value must be greater than or equal to **0**.|
| satelliteIds | Array&lt;number&gt; | Yes| No| Array of satellite IDs. The 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 value must be greater than **0**.|
| 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.|
| carrierFrequencies | Array&lt;number&gt; | Yes| No| Carrier frequency. The value must be greater than or equal to **0**, in Hz.|


## CachedGnssLocationsRequest

Represents a request for reporting cached GNSS locations.

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

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| reportingPeriodSec | number | Yes| Yes| Interval for reporting the cached GNSS locations, in milliseconds. The value must be greater than **0**.|
| 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**.|
| radius | number | Yes|Yes| Radius of a circular geofence. The value must be greater than **0**, in meters.|
| expiration | number | Yes|Yes| Expiration period of a geofence, in milliseconds. The value must be greater than **0**.|


## GeofenceRequest

Represents a GNSS geofencing request.

**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.|
| additionSize | number | Yes| No| Number of additional descriptions. The value must be greater than or equal to **0**. |
| isFromMock | Boolean | Yes| No| Whether the location information is from the mock location function.<br>**System API**: This is a system API.|


## ReverseGeocodingMockInfo

Represents information of the mock reverse geocoding function.

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

**System API**: This is a system API and cannot be called by third-party applications.

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| location |  [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Yes| Latitude and longitude information.|
| geoAddress |  [GeoAddress](#geoaddress) | Yes| Yes|Geographic address.|


## LocationMockConfig

Represents the mock location configuration.

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

**System API**: This is a system API and cannot be called by third-party applications.

| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| timeInterval | number | Yes| Yes| Interval at which mock locations are reported, in seconds.|
| locations | Array&lt;[Location](#location)&gt; | Yes| Yes| Array of mocked locations.|


## CountryCode

Represents country code information.

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


## 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.|
| ACCURACY | 0x201 | Location accuracy preferred.<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 preferred.<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.|
| 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

  Sets the scenario of the location request.

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

| Name| Value| Description|
| -------- | -------- | -------- |
| UNSET | 0x300 | Scenario unspecified.<br>If this option is used, [LocationRequestScenario](#locationrequest scenario) is invalid.|
| NAVIGATION | 0x301 | Navigation scenario.<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 scenario.<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 scenario.<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 service scenario.<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 scenario.<br>This option is applicable when 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.|


## LocationPrivacyType

Defines the privacy statement type.

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

**System API**: This is a system API and cannot be called by third-party applications.

| Name| Value| Description|
| -------- | -------- | -------- |
| OTHERS | 0 | Other scenarios. Reserved field.|
| STARTUP | 1 | Privacy statement displayed in the startup wizard.  |
| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.|


## CountryCodeType

Represents the country code source type.

**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 已提交
320
## geoLocationManager.on('locationChange')
S
shawn_he 已提交
321

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

S
shawn_he 已提交
324
Registers a listener for location changes with a location request initiated.
S
shawn_he 已提交
325

S
shawn_he 已提交
326
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
327 328 329 330 331

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

**Parameters**

S
shawn_he 已提交
332 333 334 335 336
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
  | request |  [LocationRequest](#locationrequest) | Yes| Location request.|
  | callback | Callback&lt;[Location](#location)&gt; | Yes| Callback used to return the location change event.|
S
shawn_he 已提交
337 338 339

**Error codes**

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

S
shawn_he 已提交
342 343 344 345 346
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
347 348

**Example**
S
shawn_he 已提交
349

S
shawn_he 已提交
350 351
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
352 353
  let requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
  let locationChange = (location) => {
S
shawn_he 已提交
354 355
      console.log('locationChanger: data: ' + JSON.stringify(location));
  };
S
shawn_he 已提交
356
  try {
S
shawn_he 已提交
357
      geoLocationManager.on('locationChange', requestInfo, locationChange);
S
shawn_he 已提交
358 359 360
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
361
  
S
shawn_he 已提交
362 363 364
  ```


S
shawn_he 已提交
365
## geoLocationManager.off('locationChange')
S
shawn_he 已提交
366

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

S
shawn_he 已提交
369 370
Unregisters the listener for location changes with the corresponding location request deleted.

S
shawn_he 已提交
371
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
372 373 374 375 376

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

**Parameters**

S
shawn_he 已提交
377 378 379 380
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
  | 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 已提交
381 382 383

**Error codes**

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

S
shawn_he 已提交
386 387 388 389 390
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
391 392

**Example**
S
shawn_he 已提交
393

S
shawn_he 已提交
394 395
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
396 397
  let requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
  let locationChange = (location) => {
S
shawn_he 已提交
398 399
      console.log('locationChanger: data: ' + JSON.stringify(location));
  };
S
shawn_he 已提交
400
  try {
S
shawn_he 已提交
401 402
      geoLocationManager.on('locationChange', requestInfo, locationChange);
      geoLocationManager.off('locationChange', locationChange);
S
shawn_he 已提交
403 404 405 406 407 408
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


S
shawn_he 已提交
409
## geoLocationManager.on('locationEnabledChange')
S
shawn_he 已提交
410

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

S
shawn_he 已提交
413
Registers a listener for location service status change events.
S
shawn_he 已提交
414 415 416 417 418

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

**Parameters**

S
shawn_he 已提交
419 420 421 422
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change event.|
  | callback | Callback&lt;boolean&gt; | Yes| Callback used to return the location service status change event.|
S
shawn_he 已提交
423 424 425

**Error codes**

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

S
shawn_he 已提交
428 429 430
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
431 432

**Example**
S
shawn_he 已提交
433

S
shawn_he 已提交
434 435
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
436
  let locationEnabledChange = (state) => {
S
shawn_he 已提交
437 438 439 440 441 442 443
      console.log('locationEnabledChange: ' + JSON.stringify(state));
  }
  try {
      geoLocationManager.on('locationEnabledChange', locationEnabledChange);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
444 445 446
  ```


S
shawn_he 已提交
447
## geoLocationManager.off('locationEnabledChange')
S
shawn_he 已提交
448

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

S
shawn_he 已提交
451
Unregisters the listener for location service status change events.
S
shawn_he 已提交
452 453 454

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

S
shawn_he 已提交
455
**Parameters**
S
shawn_he 已提交
456

S
shawn_he 已提交
457 458 459 460
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change event.|
  | 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 已提交
461 462 463

**Error codes**

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

S
shawn_he 已提交
466 467 468
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
469 470

**Example**
S
shawn_he 已提交
471

S
shawn_he 已提交
472 473
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
474
  let locationEnabledChange = (state) => {
S
shawn_he 已提交
475 476 477 478 479 480 481 482
      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 已提交
483 484 485
  ```


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

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

S
shawn_he 已提交
490
Registers a listener for cached GNSS location reports.
S
shawn_he 已提交
491

S
shawn_he 已提交
492
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
493

S
shawn_he 已提交
494
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
495 496 497

**Parameters**

S
shawn_he 已提交
498 499 500 501 502
  | 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.|
  | callback | Callback&lt;boolean&gt; | Yes| Callback used to return cached GNSS locations.|
S
shawn_he 已提交
503 504 505

**Error codes**

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

S
shawn_he 已提交
508 509 510 511 512
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
513 514

**Example**
S
shawn_he 已提交
515

S
shawn_he 已提交
516 517
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
518
  let cachedLocationsCb = (locations) => {
S
shawn_he 已提交
519 520
      console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
  }
S
shawn_he 已提交
521
  let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
S
shawn_he 已提交
522
  try {
S
shawn_he 已提交
523
      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
S
shawn_he 已提交
524 525 526 527 528 529
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


S
shawn_he 已提交
530
## geoLocationManager.off('cachedGnssLocationsChange')
S
shawn_he 已提交
531

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

S
shawn_he 已提交
534
Unregisters the listener for cached GNSS location reports.
S
shawn_he 已提交
535

S
shawn_he 已提交
536
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
537

S
shawn_he 已提交
538
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
539

S
shawn_he 已提交
540
**Parameters**
S
shawn_he 已提交
541

S
shawn_he 已提交
542 543 544 545
  | 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 已提交
546 547 548

**Error codes**

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

S
shawn_he 已提交
551 552 553 554 555
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
556 557

**Example**
S
shawn_he 已提交
558

S
shawn_he 已提交
559 560
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
561
  let cachedLocationsCb = (locations) => {
S
shawn_he 已提交
562 563
      console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
  }
S
shawn_he 已提交
564
  let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
S
shawn_he 已提交
565 566 567 568 569 570
  try {
      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
      geoLocationManager.off('cachedGnssLocationsChange');
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
571 572 573
  ```


S
shawn_he 已提交
574
## geoLocationManager.on('satelliteStatusChange')
S
shawn_he 已提交
575

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

S
shawn_he 已提交
578
Registers a listener for GNSS satellite status change events.
S
shawn_he 已提交
579

S
shawn_he 已提交
580
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
581

S
shawn_he 已提交
582
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
583 584 585

**Parameters**

S
shawn_he 已提交
586 587 588 589
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change event.|
  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | Yes| Callback used to return GNSS satellite status changes.|
S
shawn_he 已提交
590 591 592

**Error codes**

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

S
shawn_he 已提交
595 596 597 598
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
599 600

**Example**
S
shawn_he 已提交
601

S
shawn_he 已提交
602 603
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
604
  let gnssStatusCb = (satelliteStatusInfo) => {
S
shawn_he 已提交
605 606 607 608 609 610 611 612
      console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
  }

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


S
shawn_he 已提交
616
## geoLocationManager.off('satelliteStatusChange')
S
shawn_he 已提交
617

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

S
shawn_he 已提交
620
Unregisters the listener for GNSS satellite status change events.
S
shawn_he 已提交
621

S
shawn_he 已提交
622
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
623

S
shawn_he 已提交
624
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
625 626 627

**Parameters**

S
shawn_he 已提交
628 629 630 631
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change event.|
  | 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 已提交
632 633 634

**Error codes**

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

S
shawn_he 已提交
637 638 639 640
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
641 642


S
shawn_he 已提交
643
**Example**
S
shawn_he 已提交
644

S
shawn_he 已提交
645 646
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
647
  let gnssStatusCb = (satelliteStatusInfo) => {
S
shawn_he 已提交
648 649 650 651 652 653 654 655
      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 已提交
656 657 658
  ```


S
shawn_he 已提交
659
## geoLocationManager.on('nmeaMessage')
S
shawn_he 已提交
660

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

S
shawn_he 已提交
663
Registers a listener for GNSS NMEA message change events.
S
shawn_he 已提交
664

S
shawn_he 已提交
665
**Permission required**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
666

S
shawn_he 已提交
667
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
668 669 670

**Parameters**

S
shawn_he 已提交
671 672 673 674
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change event.|
  | callback | Callback&lt;string&gt; | Yes| Callback used to return GNSS NMEA message changes.|
S
shawn_he 已提交
675 676 677

**Error codes**

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

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


S
shawn_he 已提交
686
**Example**
S
shawn_he 已提交
687

S
shawn_he 已提交
688 689
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
690
  let nmeaCb = (str) => {
S
shawn_he 已提交
691 692
      console.log('nmeaMessage: ' + JSON.stringify(str));
  }
S
shawn_he 已提交
693

S
shawn_he 已提交
694 695 696 697 698 699
  try {
      geoLocationManager.on('nmeaMessage', nmeaCb );
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```
S
shawn_he 已提交
700 701


S
shawn_he 已提交
702
## geoLocationManager.off('nmeaMessage')
S
shawn_he 已提交
703

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

S
shawn_he 已提交
706
Unregisters the listener for GNSS NMEA message change events.
S
shawn_he 已提交
707

S
shawn_he 已提交
708
**Permission required**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
709

S
shawn_he 已提交
710
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
711 712 713

**Parameters**

S
shawn_he 已提交
714 715 716 717
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change event.|
  | 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 已提交
718 719 720

**Error codes**

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

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


S
shawn_he 已提交
729
**Example**
S
shawn_he 已提交
730

S
shawn_he 已提交
731 732
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
733
  let nmeaCb = (str) => {
S
shawn_he 已提交
734 735 736 737 738 739 740 741 742
      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 已提交
743 744 745
  ```


S
shawn_he 已提交
746
## geoLocationManager.on('gnssFenceStatusChange')
S
shawn_he 已提交
747

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

S
shawn_he 已提交
750
Registers a listener for status change events of the specified geofence.
S
shawn_he 已提交
751

S
shawn_he 已提交
752
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
753 754

**System capability**: SystemCapability.Location.Location.Geofence
S
shawn_he 已提交
755 756 757

**Parameters**

S
shawn_he 已提交
758 759 760 761
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change event.|
  | request |  [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
S
shawn_he 已提交
762
  | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
S
shawn_he 已提交
763 764 765

**Error codes**

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

S
shawn_he 已提交
768 769 770 771 772
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301600 | Failed to operate the geofence.                                     |
S
shawn_he 已提交
773 774

**Example**
S
shawn_he 已提交
775

S
shawn_he 已提交
776 777
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
778
  import wantAgent from '@ohos.app.ability.wantAgent';
S
shawn_he 已提交
779 780 781 782 783
  
  let wantAgentInfo = {
      wants: [
          {
              bundleName: "com.example.myapplication",
S
shawn_he 已提交
784
              abilityName: "EntryAbility",
S
shawn_he 已提交
785 786 787 788 789 790 791 792 793
              action: "action1",
          }
      ],
      operationType: wantAgent.OperationType.START_ABILITY,
      requestCode: 0,
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG],
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
S
shawn_he 已提交
794
    let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
S
shawn_he 已提交
795 796 797 798 799
    try {
        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
    } catch (err) {
        console.error("errCode:" + err.code + ",errMessage:" + err.message);
    }
S
shawn_he 已提交
800 801 802 803
  });
  ```


S
shawn_he 已提交
804
## geoLocationManager.off('gnssFenceStatusChange')
S
shawn_he 已提交
805

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

S
shawn_he 已提交
808
Unregisters the listener for status change events of the specified geofence.
S
shawn_he 已提交
809

S
shawn_he 已提交
810
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
811

S
shawn_he 已提交
812 813 814
**System capability**: SystemCapability.Location.Location.Geofence

**Parameters**
S
shawn_he 已提交
815

S
shawn_he 已提交
816 817 818 819
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change event.|
  | request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
S
shawn_he 已提交
820
  | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
S
shawn_he 已提交
821 822 823

**Error codes**

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

S
shawn_he 已提交
826 827 828 829 830
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301600 | Failed to operate the geofence.                                     |
S
shawn_he 已提交
831 832

**Example**
S
shawn_he 已提交
833

S
shawn_he 已提交
834 835
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
836
  import wantAgent from '@ohos.app.ability.wantAgent';
S
shawn_he 已提交
837 838 839 840 841
  
  let wantAgentInfo = {
      wants: [
          {
              bundleName: "com.example.myapplication",
S
shawn_he 已提交
842
              abilityName: "EntryAbility",
S
shawn_he 已提交
843 844 845 846 847 848 849 850 851
              action: "action1",
          }
      ],
      operationType: wantAgent.OperationType.START_ABILITY,
      requestCode: 0,
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
S
shawn_he 已提交
852
    let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
S
shawn_he 已提交
853 854 855 856 857 858
    try {
        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
        geoLocationManager.off('gnssFenceStatusChange', requestInfo, wantAgentObj);
    } catch (err) {
        console.error("errCode:" + err.code + ",errMessage:" + err.message);
    }
S
shawn_he 已提交
859 860 861 862
  });
  ```


S
shawn_he 已提交
863
## geoLocationManager.on('countryCodeChange')
S
shawn_he 已提交
864

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

S
shawn_he 已提交
867
Registers a listener for country code change events.
S
shawn_he 已提交
868 869 870 871 872

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

**Parameters**

S
shawn_he 已提交
873 874 875 876
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change event.|
  | callback | Callback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to return the country code change event.|
S
shawn_he 已提交
877 878 879

**Error codes**

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

S
shawn_he 已提交
882 883 884 885 886
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301500 | Failed to query the area information.                                       |
S
shawn_he 已提交
887 888


S
shawn_he 已提交
889
**Example**
S
shawn_he 已提交
890

S
shawn_he 已提交
891 892
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
893
  let callback = (code) => {
S
shawn_he 已提交
894 895 896 897 898 899 900 901
      console.log('countryCodeChange: ' + JSON.stringify(code));
  }

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


S
shawn_he 已提交
905 906 907
## geoLocationManager.off('countryCodeChange')

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

S
shawn_he 已提交
909
Unregisters the listener for country code change events.
S
shawn_he 已提交
910 911 912

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

S
shawn_he 已提交
913
**Parameters**
S
shawn_he 已提交
914

S
shawn_he 已提交
915 916 917 918
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change event.|
  | 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 已提交
919 920 921

**Error codes**

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

S
shawn_he 已提交
924 925 926 927 928
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301500 | Failed to query the area information.                                       |
S
shawn_he 已提交
929 930

**Example**
S
shawn_he 已提交
931

S
shawn_he 已提交
932 933
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
934
  let callback = (code) => {
S
shawn_he 已提交
935 936 937 938 939 940 941 942 943
      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 已提交
944 945 946 947
  ```



S
shawn_he 已提交
948
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
949

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

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

S
shawn_he 已提交
954
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
955 956

**System capability**: SystemCapability.Location.Location.Core
S
shawn_he 已提交
957 958 959

**Parameters**

S
shawn_he 已提交
960 961 962 963
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [CurrentLocationRequest](#currentlocationrequest) | Yes| Location request.|
  | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the current location.|
S
shawn_he 已提交
964 965 966

**Error codes**

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

S
shawn_he 已提交
969 970 971 972 973
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
974 975

**Example**
S
shawn_he 已提交
976

S
shawn_he 已提交
977 978
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
979 980
  let requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
  let locationChange = (err, location) => {
S
shawn_he 已提交
981
      if (err) {
S
shawn_he 已提交
982
          console.log('locationChanger: err=' + JSON.stringify(err));
S
shawn_he 已提交
983
      }
S
shawn_he 已提交
984 985 986 987 988 989 990 991 992 993
      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 已提交
994 995
  ```

S
shawn_he 已提交
996
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
997

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

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

S
shawn_he 已提交
1002
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1003 1004 1005

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

S
shawn_he 已提交
1006
**Parameters**
S
shawn_he 已提交
1007

S
shawn_he 已提交
1008 1009 1010
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the current location.|
S
shawn_he 已提交
1011 1012 1013

**Error codes**

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

S
shawn_he 已提交
1016 1017 1018 1019 1020
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
1021 1022

**Example**
S
shawn_he 已提交
1023

S
shawn_he 已提交
1024 1025
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1026
  let locationChange = (err, location) => {
S
shawn_he 已提交
1027 1028
      if (err) {
          console.log('locationChanger: err=' + JSON.stringify(err));
S
shawn_he 已提交
1029
      }
S
shawn_he 已提交
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
      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 已提交
1040 1041
  ```

S
shawn_he 已提交
1042
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
1043

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

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

S
shawn_he 已提交
1048
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1049 1050 1051 1052 1053

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

**Parameters**

S
shawn_he 已提交
1054 1055 1056 1057 1058 1059 1060 1061 1062
  | 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 已提交
1063 1064 1065

**Error codes**

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

S
shawn_he 已提交
1068 1069 1070 1071 1072
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
1073 1074

**Example**
S
shawn_he 已提交
1075

S
shawn_he 已提交
1076 1077
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1078
  let requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
S
shawn_he 已提交
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
  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 已提交
1098
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118

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

**Return value**

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

**Error codes**

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

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

S
shawn_he 已提交
1120 1121 1122
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
S
shawn_he 已提交
1123
      let location = geoLocationManager.getLastLocation();
S
shawn_he 已提交
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
  } 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**

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

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

**Example**

  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
S
shawn_he 已提交
1157
      let locationEnabled = geoLocationManager.isLocationEnabled();
S
shawn_he 已提交
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
  } 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.

**System API**: This is a system API and cannot be called by third-party applications.

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

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the error message.|

**Error codes**

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

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

**Example**
S
shawn_he 已提交
1191

S
shawn_he 已提交
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
  ```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.

**System API**: This is a system API and cannot be called by third-party applications.

**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**

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

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

**Example**
S
shawn_he 已提交
1233

S
shawn_he 已提交
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
  ```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.

**System API**: This is a system API and cannot be called by third-party applications.

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

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

**Error codes**

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

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

**Example**
S
shawn_he 已提交
1269

S
shawn_he 已提交
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
  ```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 已提交
1285
Converts coordinates into geographic descriptions through reverse geocoding. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the reverse geocoding result.|

**Error codes**

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

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

**Example**
S
shawn_he 已提交
1306

S
shawn_he 已提交
1307 1308
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1309
  let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
S
shawn_he 已提交
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328
  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 已提交
1329
Converts coordinates into geographic descriptions through reverse geocoding. This API uses a promise to return the result. 
S
shawn_he 已提交
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354

**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**

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

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

**Example**
S
shawn_he 已提交
1355

S
shawn_he 已提交
1356 1357
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1358
  let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
S
shawn_he 已提交
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
  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 已提交
1376
Converts geographic descriptions into coordinates through geocoding. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the geocoding result.|

**Error codes**

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

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

**Example**
S
shawn_he 已提交
1397

S
shawn_he 已提交
1398 1399
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1400
  let geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
S
shawn_he 已提交
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419
  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 已提交
1420
Converts geographic descriptions into coordinates through geocoding. This API uses a promise to return the result. 
S
shawn_he 已提交
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445

**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**

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

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

**Example**
S
shawn_he 已提交
1446

S
shawn_he 已提交
1447 1448
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1449
  let geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
S
shawn_he 已提交
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
  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**

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

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

**Example**
S
shawn_he 已提交
1485

S
shawn_he 已提交
1486 1487 1488
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
S
shawn_he 已提交
1489
      let isAvailable = geoLocationManager.isGeocoderAvailable();
S
shawn_he 已提交
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
  } 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 已提交
1502
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of cached GNSS locations. |

**Error codes**

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

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

**Example**
S
shawn_he 已提交
1522

S
shawn_he 已提交
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545
  ```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 已提交
1546
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565

**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**

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

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

**Example**
S
shawn_he 已提交
1566

S
shawn_he 已提交
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
  ```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 已提交
1588
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the error message.|

**Error codes**

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

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

S
shawn_he 已提交
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
  ```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 已提交
1622 1623


S
shawn_he 已提交
1624
## geoLocationManager.flushCachedGnssLocations
S
shawn_he 已提交
1625

S
shawn_he 已提交
1626 1627 1628 1629
flushCachedGnssLocations(): Promise&lt;void&gt;;

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

S
shawn_he 已提交
1630
**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650

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

**Return value**

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

**Error codes**

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

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

S
shawn_he 已提交
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671
  ```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 已提交
1672 1673 1674

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

S
shawn_he 已提交
1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690
**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | command |  [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the error code.|

**Error codes**

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

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

**Example**
S
shawn_he 已提交
1691

S
shawn_he 已提交
1692 1693
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1694
  let requestInfo = {'scenario': 0x301, 'command': "command_1"};
S
shawn_he 已提交
1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713
  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 已提交
1714 1715 1716

**Parameters**

S
shawn_he 已提交
1717 1718 1719
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
S
shawn_he 已提交
1720 1721 1722

**Return value**

S
shawn_he 已提交
1723 1724 1725
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;void&gt;  | void | NA | Promise used to return the error code.|
S
shawn_he 已提交
1726 1727 1728

**Error codes**

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

S
shawn_he 已提交
1731 1732 1733
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
1734 1735

**Example**
S
shawn_he 已提交
1736

S
shawn_he 已提交
1737 1738
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1739
  let requestInfo = {'scenario': 0x301, 'command': "command_1"};
S
shawn_he 已提交
1740 1741 1742 1743 1744 1745 1746 1747 1748 1749
  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 已提交
1750 1751 1752
  ```


S
shawn_he 已提交
1753
## geoLocationManager.getCountryCode
S
shawn_he 已提交
1754

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

S
shawn_he 已提交
1757
Obtains the current country code.
S
shawn_he 已提交
1758 1759 1760 1761 1762

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

**Parameters**

S
shawn_he 已提交
1763 1764 1765
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to return the country code.|
S
shawn_he 已提交
1766 1767 1768

**Error codes**

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

S
shawn_he 已提交
1771 1772 1773 1774
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301500 | Failed to query the area information.|
S
shawn_he 已提交
1775 1776

**Example**
S
shawn_he 已提交
1777

S
shawn_he 已提交
1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806
  ```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 已提交
1807
  | Promise&lt;[CountryCode](#countrycode)&gt; | [CountryCode](#countrycode) | NA | Promise used to return the country code.|
S
shawn_he 已提交
1808 1809

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

S
shawn_he 已提交
1811 1812 1813 1814 1815 1816 1817 1818
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).

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

**Example**
S
shawn_he 已提交
1819

S
shawn_he 已提交
1820 1821
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832
  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 已提交
1833 1834 1835
  ```


S
shawn_he 已提交
1836
## geoLocationManager.enableLocationMock
S
shawn_he 已提交
1837

S
shawn_he 已提交
1838
enableLocationMock(): void;
S
shawn_he 已提交
1839

S
shawn_he 已提交
1840
Enables the mock location function.
S
shawn_he 已提交
1841 1842 1843 1844 1845

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

**System API**: This is a system API and cannot be called by third-party applications.

S
shawn_he 已提交
1846 1847 1848 1849 1850 1851 1852 1853 1854 1855
**Error codes**

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

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

**Example**
S
shawn_he 已提交
1856

S
shawn_he 已提交
1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869
  ```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 已提交
1870

S
shawn_he 已提交
1871 1872 1873 1874 1875
Disables the mock location function.

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

**System API**: This is a system API and cannot be called by third-party applications.
S
shawn_he 已提交
1876 1877 1878

**Error codes**

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

S
shawn_he 已提交
1881 1882 1883 1884
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.|
S
shawn_he 已提交
1885 1886

**Example**
S
shawn_he 已提交
1887

S
shawn_he 已提交
1888 1889
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1890 1891 1892 1893 1894
  try {
      geoLocationManager.disableLocationMock();
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1895 1896 1897
  ```


S
shawn_he 已提交
1898
## geoLocationManager.setMockedLocations
S
shawn_he 已提交
1899

S
shawn_he 已提交
1900
setMockedLocations(config: LocationMockConfig): void;
S
shawn_he 已提交
1901

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

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

S
shawn_he 已提交
1906 1907 1908 1909 1910 1911
**System capability**: SystemCapability.Location.Location.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

S
shawn_he 已提交
1912 1913 1914
  | 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 已提交
1915 1916 1917

**Error codes**

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

S
shawn_he 已提交
1920 1921 1922 1923
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.|
S
shawn_he 已提交
1924 1925

**Example**
S
shawn_he 已提交
1926

S
shawn_he 已提交
1927 1928
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1929
  let locations = [
S
shawn_he 已提交
1930 1931 1932 1933 1934 1935
      {"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 已提交
1936
  let config = {"timeInterval": 5, "locations": locations};
S
shawn_he 已提交
1937
  try {
S
shawn_he 已提交
1938
      geoLocationManager.enableLocationMock();
S
shawn_he 已提交
1939 1940 1941 1942
      geoLocationManager.setMockedLocations(config);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1943 1944 1945
  ```


S
shawn_he 已提交
1946
## geoLocationManager.enableReverseGeocodingMock
S
shawn_he 已提交
1947

S
shawn_he 已提交
1948
enableReverseGeocodingMock(): void;
S
shawn_he 已提交
1949

S
shawn_he 已提交
1950
Enables the mock reverse geocoding function.
S
shawn_he 已提交
1951 1952 1953 1954 1955

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

**System API**: This is a system API and cannot be called by third-party applications.

S
shawn_he 已提交
1956 1957 1958 1959 1960 1961 1962 1963 1964
**Error codes**

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

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

**Example**
S
shawn_he 已提交
1965

S
shawn_he 已提交
1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982
  ```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 已提交
1983

S
shawn_he 已提交
1984
**System API**: This is a system API and cannot be called by third-party applications.
S
shawn_he 已提交
1985 1986 1987

**Error codes**

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

S
shawn_he 已提交
1990 1991 1992
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
1993 1994

**Example**
S
shawn_he 已提交
1995

S
shawn_he 已提交
1996 1997
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1998 1999 2000 2001 2002
  try {
      geoLocationManager.disableReverseGeocodingMock();
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
2003 2004 2005 2006 2007
  ```


## geoLocationManager.setReverseGeocodingMockInfo

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

S
shawn_he 已提交
2010
Sets information of the mock reverse geocoding function, including the mapping between a location and geographic name. If the location is contained in the configurations during reverse geocoding query, the corresponding geographic name will be returned.
S
shawn_he 已提交
2011

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

S
shawn_he 已提交
2014 2015 2016 2017 2018 2019
**System capability**: SystemCapability.Location.Location.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

S
shawn_he 已提交
2020 2021
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
2022
  | mockInfos | Array&lt;[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)&gt; | Yes| Array of information of the mock reverse geocoding function, including a location and a geographic address.|
S
shawn_he 已提交
2023 2024 2025

**Error codes**

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

S
shawn_he 已提交
2028 2029 2030
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
2031 2032

**Example**
S
shawn_he 已提交
2033

S
shawn_he 已提交
2034 2035
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2036
  let mockInfos = [
S
shawn_he 已提交
2037 2038 2039 2040 2041 2042
      {"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 已提交
2043
  try {
S
shawn_he 已提交
2044
      geoLocationManager.enableReverseGeocodingMock();
S
shawn_he 已提交
2045 2046 2047 2048
      geoLocationManager.setReverseGeocodingMockInfo(mockInfos);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
2049 2050 2051
  ```


S
shawn_he 已提交
2052
## geoLocationManager.isLocationPrivacyConfirmed
S
shawn_he 已提交
2053

S
shawn_he 已提交
2054
isLocationPrivacyConfirmed(type: LocationPrivacyType): boolean;
S
shawn_he 已提交
2055

S
shawn_he 已提交
2056
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 已提交
2057 2058 2059

**System API**: This is a system API and cannot be called by third-party applications.

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

S
shawn_he 已提交
2062 2063
**Parameters**

S
shawn_he 已提交
2064 2065 2066
  | 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 已提交
2067 2068 2069

**Return value**

S
shawn_he 已提交
2070 2071
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
2072
  | boolean  | boolean | NA | Whether the user agrees with the privacy statement.|
S
shawn_he 已提交
2073 2074 2075

**Error codes**

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

S
shawn_he 已提交
2078 2079 2080
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
2081 2082

**Example**
S
shawn_he 已提交
2083

S
shawn_he 已提交
2084 2085 2086
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
S
shawn_he 已提交
2087
      let isConfirmed = geoLocationManager.isLocationPrivacyConfirmed(1);
S
shawn_he 已提交
2088 2089 2090 2091 2092
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

S
shawn_he 已提交
2093

S
shawn_he 已提交
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110
## 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.

**System API**: This is a system API and cannot be called by third-party applications.

**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 已提交
2111
  | isConfirmed | boolean | Yes| Whether the user agrees with the privacy statement.|
S
shawn_he 已提交
2112 2113 2114 2115 2116 2117 2118 2119 2120 2121

**Error codes**

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

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

**Example**
S
shawn_he 已提交
2122

S
shawn_he 已提交
2123 2124
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
2125 2126 2127 2128 2129
  try {
      geoLocationManager.setLocationPrivacyConfirmStatus(1, true);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
2130
  ```