js-apis-geoLocationManager.md 78.3 KB
Newer Older
S
shawn_he 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# Geolocation Manager

The Geolocation Manager module provides location service management functions.

> **NOTE**
>
> 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 28 29 30 31
| API Version| Location Permission| Permission Application Result| Location Accuracy|
| -------- | -------- | -------- | -------- |
| Earlier than 9| ohos.permission.LOCATION | Success| Location accurate to meters|
| 9 and later| ohos.permission.LOCATION | Failure| No location obtained|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters|
S
shawn_he 已提交
32

S
shawn_he 已提交
33
If your application needs to access the device location information when running in the background, it must be configured to be able to run in the background and be granted the **ohos.permission.LOCATION\_IN\_BACKGROUND** permission. In this way, the system continues to report device location information after your application moves to the background.
S
shawn_he 已提交
34 35 36 37 38 39 40 41 42 43 44

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


## Modules to Import

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


S
shawn_he 已提交
45
## geoLocationManager.on('locationChange')
S
shawn_he 已提交
46

S
shawn_he 已提交
47
on(type: 'locationChange', request: LocationRequest, callback: Callback<Location>): void
S
shawn_he 已提交
48

S
shawn_he 已提交
49 50 51
Registers a listener for location changes with a location request initiated. The location result is reported through [LocationRequest](#locationrequest).

**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
52 53 54 55 56

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

**Parameters**

S
shawn_he 已提交
57 58 59 60 61
  | 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<[Location](#location)> | Yes| Callback used to return the location change event.|
S
shawn_he 已提交
62 63 64

**Error codes**

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

S
shawn_he 已提交
67 68 69 70 71
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
72 73

**Example**
S
shawn_he 已提交
74
  
S
shawn_he 已提交
75 76
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
77 78 79 80
  var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
  var locationChange = (location) => {
      console.log('locationChanger: data: ' + JSON.stringify(location));
  };
S
shawn_he 已提交
81
  try {
S
shawn_he 已提交
82
      geoLocationManager.on('locationChange', requestInfo, locationChange);
S
shawn_he 已提交
83 84 85
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
86
  
S
shawn_he 已提交
87 88 89
  ```


S
shawn_he 已提交
90
## geoLocationManager.off('locationChange')
S
shawn_he 已提交
91

S
shawn_he 已提交
92
off(type: 'locationChange', callback?: Callback<Location>): void
S
shawn_he 已提交
93

S
shawn_he 已提交
94 95 96
Unregisters the listener for location changes with the corresponding location request deleted.

**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
97 98 99 100 101

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

**Parameters**

S
shawn_he 已提交
102 103 104 105
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
  | callback | Callback<[Location](#location)> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
106 107 108

**Error codes**

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

S
shawn_he 已提交
111 112 113 114 115
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
116 117

**Example**
S
shawn_he 已提交
118
  
S
shawn_he 已提交
119 120
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
121 122 123 124
  var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
  var locationChange = (location) => {
      console.log('locationChanger: data: ' + JSON.stringify(location));
  };
S
shawn_he 已提交
125
  try {
S
shawn_he 已提交
126 127
      geoLocationManager.on('locationChange', requestInfo, locationChange);
      geoLocationManager.off('locationChange', locationChange);
S
shawn_he 已提交
128 129 130 131 132 133
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


S
shawn_he 已提交
134
## geoLocationManager.on('locationEnabledChange')
S
shawn_he 已提交
135

S
shawn_he 已提交
136
on(type: 'locationEnabledChange', callback: Callback<boolean>): void
S
shawn_he 已提交
137

S
shawn_he 已提交
138
Registers a listener for location service status change events.
S
shawn_he 已提交
139 140 141 142 143

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

**Parameters**

S
shawn_he 已提交
144 145 146 147
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change event.|
  | callback | Callback<boolean> | Yes| Callback used to return the location service status change event.|
S
shawn_he 已提交
148 149 150

**Error codes**

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

S
shawn_he 已提交
153 154 155
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
156 157

**Example**
S
shawn_he 已提交
158
  
S
shawn_he 已提交
159 160
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
161 162 163 164 165 166 167 168
  var locationEnabledChange = (state) => {
      console.log('locationEnabledChange: ' + JSON.stringify(state));
  }
  try {
      geoLocationManager.on('locationEnabledChange', locationEnabledChange);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
169 170 171
  ```


S
shawn_he 已提交
172
## geoLocationManager.off('locationEnabledChange')
S
shawn_he 已提交
173

S
shawn_he 已提交
174
off(type: 'locationEnabledChange', callback?: Callback<boolean>): void;
S
shawn_he 已提交
175

S
shawn_he 已提交
176
Unregisters the listener for location service status change events.
S
shawn_he 已提交
177 178 179

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

S
shawn_he 已提交
180
**Parameters**
S
shawn_he 已提交
181

S
shawn_he 已提交
182 183 184 185
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change event.|
  | callback | Callback<boolean> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
186 187 188

**Error codes**

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

S
shawn_he 已提交
191 192 193
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
194 195

**Example**
S
shawn_he 已提交
196
  
S
shawn_he 已提交
197 198
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
199 200 201 202 203 204 205 206 207
  var locationEnabledChange = (state) => {
      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 已提交
208 209 210
  ```


S
shawn_he 已提交
211
## geoLocationManager.on('cachedGnssLocationsChange')
S
shawn_he 已提交
212

S
shawn_he 已提交
213
on(type: 'cachedGnssLocationsChange', request: CachedGnssLocationsRequest, callback: Callback<Array<Location>>): void;
S
shawn_he 已提交
214

S
shawn_he 已提交
215
Registers a listener for cached GNSS location reports.
S
shawn_he 已提交
216

S
shawn_he 已提交
217
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
218

S
shawn_he 已提交
219
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
220 221 222

**Parameters**

S
shawn_he 已提交
223 224 225 226 227
  | 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<boolean> | Yes| Callback used to return cached GNSS locations.|
S
shawn_he 已提交
228 229 230

**Error codes**

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

S
shawn_he 已提交
233 234 235 236 237
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
238 239

**Example**
S
shawn_he 已提交
240
  
S
shawn_he 已提交
241 242
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
243 244 245 246
  var cachedLocationsCb = (locations) => {
      console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
  }
  var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
S
shawn_he 已提交
247
  try {
S
shawn_he 已提交
248
      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
S
shawn_he 已提交
249 250 251 252 253 254
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


S
shawn_he 已提交
255
## geoLocationManager.off('cachedGnssLocationsChange')
S
shawn_he 已提交
256

S
shawn_he 已提交
257
off(type: 'cachedGnssLocationsChange', callback?: Callback<Array<Location>>): void;
S
shawn_he 已提交
258

S
shawn_he 已提交
259
Unregisters the listener for cached GNSS location reports.
S
shawn_he 已提交
260

S
shawn_he 已提交
261
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
262

S
shawn_he 已提交
263
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
264

S
shawn_he 已提交
265
**Parameters**
S
shawn_he 已提交
266

S
shawn_he 已提交
267 268 269 270
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.|
  | callback | Callback<boolean> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
271 272 273

**Error codes**

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

S
shawn_he 已提交
276 277 278 279 280
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.                                       |
S
shawn_he 已提交
281 282

**Example**
S
shawn_he 已提交
283
  
S
shawn_he 已提交
284 285
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
286 287 288 289 290 291 292 293 294 295
  var cachedLocationsCb = (locations) => {
      console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
  }
  var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
  try {
      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
      geoLocationManager.off('cachedGnssLocationsChange');
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
296 297 298
  ```


S
shawn_he 已提交
299
## geoLocationManager.on('satelliteStatusChange')
S
shawn_he 已提交
300

S
shawn_he 已提交
301
on(type: 'satelliteStatusChange', callback: Callback<SatelliteStatusInfo>): void;
S
shawn_he 已提交
302

S
shawn_he 已提交
303
Registers a listener for GNSS satellite status change events.
S
shawn_he 已提交
304

S
shawn_he 已提交
305
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
306

S
shawn_he 已提交
307
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
308 309 310

**Parameters**

S
shawn_he 已提交
311 312 313 314
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change event.|
  | callback | Callback<[SatelliteStatusInfo](#satellitestatusinfo)> | Yes| Callback used to return GNSS satellite status changes.|
S
shawn_he 已提交
315 316 317

**Error codes**

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

S
shawn_he 已提交
320 321 322 323
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
324 325

**Example**
S
shawn_he 已提交
326
  
S
shawn_he 已提交
327 328
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
329 330 331 332 333 334 335 336 337
  var gnssStatusCb = (satelliteStatusInfo) => {
      console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
  }

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


S
shawn_he 已提交
341
## geoLocationManager.off('satelliteStatusChange')
S
shawn_he 已提交
342

S
shawn_he 已提交
343
off(type: 'satelliteStatusChange', callback?: Callback<SatelliteStatusInfo>): void;
S
shawn_he 已提交
344

S
shawn_he 已提交
345
Unregisters the listener for GNSS satellite status change events.
S
shawn_he 已提交
346

S
shawn_he 已提交
347
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
348

S
shawn_he 已提交
349
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
350 351 352

**Parameters**

S
shawn_he 已提交
353 354 355 356
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change event.|
  | callback | Callback<[SatelliteStatusInfo](#satellitestatusinfo)> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
357 358 359

**Error codes**

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

S
shawn_he 已提交
362 363 364 365
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
366 367


S
shawn_he 已提交
368 369
**Example**
  
S
shawn_he 已提交
370 371
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
372 373 374 375 376 377 378 379 380
  var gnssStatusCb = (satelliteStatusInfo) => {
      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 已提交
381 382 383
  ```


S
shawn_he 已提交
384
## geoLocationManager.on('nmeaMessage')
S
shawn_he 已提交
385

S
shawn_he 已提交
386
on(type: 'nmeaMessage', callback: Callback<string>): void;
S
shawn_he 已提交
387

S
shawn_he 已提交
388
Registers a listener for GNSS NMEA message change events.
S
shawn_he 已提交
389

S
shawn_he 已提交
390
**Permission required**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
391

S
shawn_he 已提交
392
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
393 394 395

**Parameters**

S
shawn_he 已提交
396 397 398 399
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change event.|
  | callback | Callback<string> | Yes| Callback used to return GNSS NMEA message changes.|
S
shawn_he 已提交
400 401 402

**Error codes**

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

S
shawn_he 已提交
405 406 407 408
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
409 410


S
shawn_he 已提交
411 412
**Example**
  
S
shawn_he 已提交
413 414
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
415 416 417
  var nmeaCb = (str) => {
      console.log('nmeaMessage: ' + JSON.stringify(str));
  }
S
shawn_he 已提交
418

S
shawn_he 已提交
419 420 421 422 423 424
  try {
      geoLocationManager.on('nmeaMessage', nmeaCb );
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```
S
shawn_he 已提交
425 426


S
shawn_he 已提交
427
## geoLocationManager.off('nmeaMessage')
S
shawn_he 已提交
428

S
shawn_he 已提交
429
off(type: 'nmeaMessage', callback?: Callback<string>): void;
S
shawn_he 已提交
430

S
shawn_he 已提交
431
Unregisters the listener for GNSS NMEA message change events.
S
shawn_he 已提交
432

S
shawn_he 已提交
433
**Permission required**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
434

S
shawn_he 已提交
435
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
436 437 438

**Parameters**

S
shawn_he 已提交
439 440 441 442
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change event.|
  | callback | Callback<string> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
443 444 445

**Error codes**

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

S
shawn_he 已提交
448 449 450 451
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
S
shawn_he 已提交
452 453


S
shawn_he 已提交
454 455
**Example**
  
S
shawn_he 已提交
456 457
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
458 459 460 461 462 463 464 465 466 467
  var nmeaCb = (str) => {
      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 已提交
468 469 470
  ```


S
shawn_he 已提交
471
## geoLocationManager.on('gnssFenceStatusChange')
S
shawn_he 已提交
472

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

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

S
shawn_he 已提交
477 478 479
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION

**System capability**: SystemCapability.Location.Location.Geofence
S
shawn_he 已提交
480 481 482

**Parameters**

S
shawn_he 已提交
483 484 485 486 487
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change event.|
  | request |  [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
  | want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
S
shawn_he 已提交
488 489 490

**Error codes**

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

S
shawn_he 已提交
493 494 495 496 497
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301600 | Failed to operate the geofence.                                     |
S
shawn_he 已提交
498 499

**Example**
S
shawn_he 已提交
500
  
S
shawn_he 已提交
501 502
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
  import wantAgent from '@ohos.wantAgent';
  
  let wantAgentInfo = {
      wants: [
          {
              bundleName: "com.example.myapplication",
              abilityName: "com.example.myapplication.MainAbility",
              action: "action1",
          }
      ],
      operationType: wantAgent.OperationType.START_ABILITY,
      requestCode: 0,
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG],
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
    var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
    try {
        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
    } catch (err) {
        console.error("errCode:" + err.code + ",errMessage:" + err.message);
    }
S
shawn_he 已提交
525 526 527 528
  });
  ```


S
shawn_he 已提交
529
## geoLocationManager.off('gnssFenceStatusChange')
S
shawn_he 已提交
530

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

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

S
shawn_he 已提交
535
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
536

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

**Parameters**
S
shawn_he 已提交
540

S
shawn_he 已提交
541 542 543 544 545
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change event.|
  | request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
  | want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
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.                                                 |
|3301600 | Failed to operate the geofence.                                     |
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 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
  import wantAgent from '@ohos.wantAgent';
  
  let wantAgentInfo = {
      wants: [
          {
              bundleName: "com.example.myapplication",
              abilityName: "com.example.myapplication.MainAbility",
              action: "action1",
          }
      ],
      operationType: wantAgent.OperationType.START_ABILITY,
      requestCode: 0,
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
    var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
    try {
        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
        geoLocationManager.off('gnssFenceStatusChange', requestInfo, wantAgentObj);
    } catch (err) {
        console.error("errCode:" + err.code + ",errMessage:" + err.message);
    }
S
shawn_he 已提交
584 585 586 587
  });
  ```


S
shawn_he 已提交
588
## geoLocationManager.on('countryCodeChange')
S
shawn_he 已提交
589

S
shawn_he 已提交
590
on(type: 'countryCodeChange', callback: Callback<CountryCode>): void;
S
shawn_he 已提交
591

S
shawn_he 已提交
592
Registers a listener for country code change events.
S
shawn_he 已提交
593 594 595 596 597

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

**Parameters**

S
shawn_he 已提交
598 599 600 601
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change event.|
  | callback | Callback<[CountryCode](#countrycode)> | Yes| Callback used to return the country code change event.|
S
shawn_he 已提交
602 603 604

**Error codes**

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

S
shawn_he 已提交
607 608 609 610 611
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301500 | Failed to query the area information.                                       |
S
shawn_he 已提交
612 613


S
shawn_he 已提交
614 615
**Example**
  
S
shawn_he 已提交
616 617
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
618 619 620 621 622 623 624 625 626
  var callback = (code) => {
      console.log('countryCodeChange: ' + JSON.stringify(code));
  }

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


S
shawn_he 已提交
630 631 632
## geoLocationManager.off('countryCodeChange')

off(type: 'countryCodeChange', callback?: Callback<CountryCode>): void;
S
shawn_he 已提交
633

S
shawn_he 已提交
634
Unregisters the listener for country code change events.
S
shawn_he 已提交
635 636 637

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

S
shawn_he 已提交
638
**Parameters**
S
shawn_he 已提交
639

S
shawn_he 已提交
640 641 642 643
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change event.|
  | callback | Callback<[CountryCode](#countrycode)> | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
644 645 646

**Error codes**

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

S
shawn_he 已提交
649 650 651 652 653
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301500 | Failed to query the area information.                                       |
S
shawn_he 已提交
654 655

**Example**
S
shawn_he 已提交
656
  
S
shawn_he 已提交
657 658
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
659 660 661 662 663 664 665 666 667 668
  var callback = (code) => {
      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 已提交
669 670 671 672
  ```



S
shawn_he 已提交
673
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
674

S
shawn_he 已提交
675
getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback<Location>): void
S
shawn_he 已提交
676

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

S
shawn_he 已提交
679 680 681
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION

**System capability**: SystemCapability.Location.Location.Core
S
shawn_he 已提交
682 683 684

**Parameters**

S
shawn_he 已提交
685 686 687 688
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [CurrentLocationRequest](#currentlocationrequest) | Yes| Location request.|
  | callback | AsyncCallback<[Location](#location)> | Yes| Callback used to return the current location.|
S
shawn_he 已提交
689 690 691

**Error codes**

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

S
shawn_he 已提交
694 695 696 697 698
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
699 700

**Example**
S
shawn_he 已提交
701
  
S
shawn_he 已提交
702 703
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
704 705
  var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
  var locationChange = (err, location) => {
S
shawn_he 已提交
706
      if (err) {
S
shawn_he 已提交
707
          console.log('locationChanger: err=' + JSON.stringify(err));
S
shawn_he 已提交
708
      }
S
shawn_he 已提交
709 710 711 712 713 714 715 716 717 718
      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 已提交
719 720
  ```

S
shawn_he 已提交
721
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
722

S
shawn_he 已提交
723
getCurrentLocation(callback: AsyncCallback<Location>): void;
S
shawn_he 已提交
724

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

S
shawn_he 已提交
727
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
728 729 730

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

S
shawn_he 已提交
731
**Parameters**
S
shawn_he 已提交
732

S
shawn_he 已提交
733 734 735
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback<[Location](#location)> | Yes| Callback used to return the current location.|
S
shawn_he 已提交
736 737 738

**Error codes**

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

S
shawn_he 已提交
741 742 743 744 745
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
746 747

**Example**
S
shawn_he 已提交
748
  
S
shawn_he 已提交
749 750
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
751 752 753
  var locationChange = (err, location) => {
      if (err) {
          console.log('locationChanger: err=' + JSON.stringify(err));
S
shawn_he 已提交
754
      }
S
shawn_he 已提交
755 756 757 758 759 760 761 762 763 764
      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 已提交
765 766
  ```

S
shawn_he 已提交
767
## geoLocationManager.getCurrentLocation
S
shawn_he 已提交
768

S
shawn_he 已提交
769
getCurrentLocation(request?: CurrentLocationRequest): Promise<Location>
S
shawn_he 已提交
770

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

S
shawn_he 已提交
773
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
S
shawn_he 已提交
774 775 776 777 778

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

**Parameters**

S
shawn_he 已提交
779 780 781 782 783 784 785 786 787
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.|

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise<[Location](#location)>  | [Location](#location) | NA | Promise used to return the current location.|
S
shawn_he 已提交
788 789 790

**Error codes**

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

S
shawn_he 已提交
793 794 795 796 797
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301200 | Failed to obtain the geographical location.  |
S
shawn_he 已提交
798 799

**Example**
S
shawn_he 已提交
800
  
S
shawn_he 已提交
801 802
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 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 1157 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 1191 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 1233 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 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 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 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432
  var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
  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.

**Permission required**: ohos.permission.APPROXIMATELY_LOCATION

**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**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      var location = geoLocationManager.getLastLocation();
  } 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 {
      var locationEnabled = geoLocationManager.isLocationEnabled();
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.requestEnableLocation

requestEnableLocation(callback: AsyncCallback<boolean>): void

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

**Permission required**: ohos.permission.APPROXIMATELY_LOCATION

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. The value **true** indicates that the user agrees to enable the location service, and the value **false** indicates the opposite.|

**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.  |
|3301700 | No response to the request.  |

**Example**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      geoLocationManager.requestEnableLocation((err, data) => {
          if (err) {
              console.log('requestEnableLocation: err=' + JSON.stringify(err));
          }
          if (data) {
              console.log('requestEnableLocation: data=' + JSON.stringify(data));
          }
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.requestEnableLocation

requestEnableLocation(): Promise<boolean>

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

**Permission required**: ohos.permission.APPROXIMATELY_LOCATION

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

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise<boolean>  | boolean | NA | Promise used to return the result. The value **true** indicates that the user agrees to enable the location service, and the value **false** indicates the opposite.|

**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.  |
|3301700 | No response to the request.  |

**Example**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      geoLocationManager.requestEnableLocation().then((result) => {
          console.log('promise, requestEnableLocation: ' + JSON.stringify(result));
      })  
      .catch((error) => {
          console.log('promise, requestEnableLocation: error=' + JSON.stringify(error));
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.enableLocation

enableLocation(callback: AsyncCallback<void>): 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<void> | 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**
  
  ```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<void>

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<void>  | 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**
  
  ```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**
  
  ```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<Array<GeoAddress>>): void

Converts coordinates into geographic description through reverse geocoding. This API uses an asynchronous callback to return the result. 

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
  | callback | AsyncCallback<Array<[GeoAddress](#geoaddress)>> | 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**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
  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<Array<GeoAddress>>;

Converts coordinates into geographic description through reverse geocoding. This API uses a promise to return the result. 

**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<Array<[GeoAddress](#geoaddress)>>  | Array<[GeoAddress](#geoaddress)> | 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**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
  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<Array<GeoAddress>>): void

Converts geographic description into coordinates through geocoding. This API uses an asynchronous callback to return the result. 

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
  | callback | AsyncCallback<Array<[GeoAddress](#geoaddress)>> | 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**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
  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<Array<GeoAddress>>

Converts geographic description into coordinates through geocoding. This API uses a promise to return the result. 

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

**Parameters**

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

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise<Array<[GeoAddress](#geoaddress)>>  | Array<[GeoAddress](#geoaddress)> | 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**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
  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**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  try {
      var isAvailable = geoLocationManager.isGeocoderAvailable();
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```


## geoLocationManager.getCachedGnssLocationsSize

getCachedGnssLocationsSize(callback: AsyncCallback<number>): void;

Obtains the number of cached GNSS locations. 

**Permission required**: ohos.permission.APPROXIMATELY_LOCATION

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback<number> | 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**
  
  ```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<number>;

Obtains the number of cached GNSS locations. 

**Permission required**: ohos.permission.APPROXIMATELY_LOCATION

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

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise<number>  | 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**
  
  ```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<void>): void;

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

**Permission required**: ohos.permission.APPROXIMATELY_LOCATION

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback<void> | 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**
  
  ```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 已提交
1433 1434


S
shawn_he 已提交
1435
## geoLocationManager.flushCachedGnssLocations
S
shawn_he 已提交
1436

S
shawn_he 已提交
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 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
flushCachedGnssLocations(): Promise<void>;

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

**Permission required**: ohos.permission.APPROXIMATELY_LOCATION

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

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise<void>  | 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**
  
  ```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<void>): void;

Sends an extended command to the location subsystem. 
S
shawn_he 已提交
1483 1484 1485

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

S
shawn_he 已提交
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | command |  [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
  | callback | AsyncCallback<void> | 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**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  var requestInfo = {'scenario': 0x301, 'command': "command_1"};
  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<void>;

Sends an extended command to the location subsystem. 

**System capability**: SystemCapability.Location.Location.Core
S
shawn_he 已提交
1525 1526 1527

**Parameters**

S
shawn_he 已提交
1528 1529 1530
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
S
shawn_he 已提交
1531 1532 1533

**Return value**

S
shawn_he 已提交
1534 1535 1536
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise<void>  | void | NA | Promise used to return the error code.|
S
shawn_he 已提交
1537 1538 1539

**Error codes**

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

S
shawn_he 已提交
1542 1543 1544
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
1545 1546

**Example**
S
shawn_he 已提交
1547
  
S
shawn_he 已提交
1548 1549
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
  var requestInfo = {'scenario': 0x301, 'command': "command_1"};
  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 已提交
1561 1562 1563
  ```


S
shawn_he 已提交
1564
## geoLocationManager.getCountryCode
S
shawn_he 已提交
1565

S
shawn_he 已提交
1566
getCountryCode(callback: AsyncCallback<CountryCode>): void;
S
shawn_he 已提交
1567

S
shawn_he 已提交
1568
Obtains the current country code.
S
shawn_he 已提交
1569 1570 1571 1572 1573

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

**Parameters**

S
shawn_he 已提交
1574 1575 1576
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback<[CountryCode](#countrycode)> | Yes| Callback used to return the country code.|
S
shawn_he 已提交
1577 1578 1579

**Error codes**

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

S
shawn_he 已提交
1582 1583 1584 1585
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301500 | Failed to query the area information.|
S
shawn_he 已提交
1586 1587

**Example**
S
shawn_he 已提交
1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617
  
  ```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<CountryCode>;

Obtains the current country code.

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

**Return value**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1618
  | Promise<[CountryCode](#countrycode)> | [CountryCode](#countrycode) | NA | Callback used to return the country code.|
S
shawn_he 已提交
1619 1620

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

S
shawn_he 已提交
1622 1623 1624 1625 1626 1627 1628 1629 1630
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 已提交
1631 1632
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643
  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 已提交
1644 1645 1646
  ```


S
shawn_he 已提交
1647
## geoLocationManager.enableLocationMock
S
shawn_he 已提交
1648

S
shawn_he 已提交
1649
enableLocationMock(): void;
S
shawn_he 已提交
1650

S
shawn_he 已提交
1651
Enables the mock location function.
S
shawn_he 已提交
1652 1653 1654 1655 1656

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

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

S
shawn_he 已提交
1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680
**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**
  
  ```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 已提交
1681

S
shawn_he 已提交
1682 1683 1684 1685 1686
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 已提交
1687 1688 1689

**Error codes**

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

S
shawn_he 已提交
1692 1693 1694 1695
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.|
S
shawn_he 已提交
1696 1697

**Example**
S
shawn_he 已提交
1698
  
S
shawn_he 已提交
1699 1700
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1701 1702 1703 1704 1705
  try {
      geoLocationManager.disableLocationMock();
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1706 1707 1708
  ```


S
shawn_he 已提交
1709
## geoLocationManager.setMockedLocations
S
shawn_he 已提交
1710

S
shawn_he 已提交
1711
setMockedLocations(config: LocationMockConfig): void;
S
shawn_he 已提交
1712

S
shawn_he 已提交
1713
Sets the mock location information. The mock locations will be reported at the interval specified in this API.
S
shawn_he 已提交
1714 1715 1716 1717 1718 1719 1720

**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 已提交
1721 1722 1723
  | 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 已提交
1724 1725 1726

**Error codes**

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

S
shawn_he 已提交
1729 1730 1731 1732
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.|
S
shawn_he 已提交
1733 1734

**Example**
S
shawn_he 已提交
1735
  
S
shawn_he 已提交
1736 1737
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
  var locations = [
      {"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}
  ];
  var config = {"timeInterval": 5, "locations": locations};
  try {
      geoLocationManager.setMockedLocations(config);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1751 1752 1753
  ```


S
shawn_he 已提交
1754
## geoLocationManager.enableReverseGeocodingMock
S
shawn_he 已提交
1755

S
shawn_he 已提交
1756
enableReverseGeocodingMock(): void;
S
shawn_he 已提交
1757

S
shawn_he 已提交
1758
Enables the mock reverse geocoding function.
S
shawn_he 已提交
1759 1760 1761 1762 1763

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

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

S
shawn_he 已提交
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790
**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 {
      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 已提交
1791

S
shawn_he 已提交
1792
**System API**: This is a system API and cannot be called by third-party applications.
S
shawn_he 已提交
1793 1794 1795

**Error codes**

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

S
shawn_he 已提交
1798 1799 1800
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
1801 1802

**Example**
S
shawn_he 已提交
1803
  
S
shawn_he 已提交
1804 1805
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1806 1807 1808 1809 1810
  try {
      geoLocationManager.disableReverseGeocodingMock();
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1811 1812 1813 1814 1815
  ```


## geoLocationManager.setReverseGeocodingMockInfo

S
shawn_he 已提交
1816
setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>): void;
S
shawn_he 已提交
1817

S
shawn_he 已提交
1818
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 已提交
1819 1820 1821 1822 1823 1824 1825

**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 已提交
1826 1827
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1828
  | mockInfos | Array<[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)> | Yes| Array of information of the mock reverse geocoding function, including a location and a geographic name.|
S
shawn_he 已提交
1829 1830 1831

**Error codes**

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

S
shawn_he 已提交
1834 1835 1836
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
1837 1838

**Example**
S
shawn_he 已提交
1839
  
S
shawn_he 已提交
1840 1841 1842 1843 1844 1845 1846 1847 1848
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  var mockInfos = [
      {"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 已提交
1849 1850 1851 1852 1853
  try {
      geoLocationManager.setReverseGeocodingMockInfo(mockInfos);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1854 1855 1856
  ```


S
shawn_he 已提交
1857
## geoLocationManager.isLocationPrivacyConfirmed
S
shawn_he 已提交
1858

S
shawn_he 已提交
1859
isLocationPrivacyConfirmed(type: LocationPrivacyType): boolean;
S
shawn_he 已提交
1860

S
shawn_he 已提交
1861
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 已提交
1862 1863 1864

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

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

S
shawn_he 已提交
1867 1868
**Parameters**

S
shawn_he 已提交
1869 1870 1871
  | 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 已提交
1872 1873 1874

**Return value**

S
shawn_he 已提交
1875 1876
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1877
  | boolean  | boolean | NA | Result indicating whether the user agrees with the privacy statement.|
S
shawn_he 已提交
1878 1879 1880

**Error codes**

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

S
shawn_he 已提交
1883 1884 1885
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
S
shawn_he 已提交
1886 1887

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

S
shawn_he 已提交
1898

S
shawn_he 已提交
1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915
## 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 已提交
1916
  | isConfirmed | boolean | Yes| Whether the user agrees with the privacy statement.|
S
shawn_he 已提交
1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927

**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 已提交
1928 1929
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
S
shawn_he 已提交
1930 1931 1932 1933 1934
  try {
      geoLocationManager.setLocationPrivacyConfirmStatus(1, true);
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
S
shawn_he 已提交
1935 1936 1937 1938 1939 1940 1941 1942 1943
  ```


## LocationRequestPriority

Sets the priority of the location request.

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

S
shawn_he 已提交
1944 1945 1946 1947 1948
| Name| Value| Description|
| -------- | -------- | -------- |
| UNSET | 0x200 | Priority unspecified.|
| ACCURACY | 0x201 | Location accuracy.|
| LOW_POWER | 0x202 | Power efficiency.|
S
shawn_he 已提交
1949 1950 1951 1952 1953 1954 1955 1956 1957
| FIRST_FIX | 0x203 | Fast location. Use this option if you want to obtain a location as fast as possible.|


## LocationRequestScenario

  Sets the scenario of the location request.

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

S
shawn_he 已提交
1958 1959 1960 1961 1962 1963 1964 1965
| Name| Value| Description|
| -------- | -------- | -------- |
| UNSET | 0x300 | Scenario unspecified.|
| NAVIGATION | 0x301 | Navigation.|
| TRAJECTORY_TRACKING | 0x302 | Trajectory tracking.|
| CAR_HAILING | 0x303 | Ride hailing.|
| DAILY_LIFE_SERVICE | 0x304 | Daily life services.|
| NO_POWER | 0x305 | Power efficiency. Your application does not proactively start the location service. When responding to another application requesting the same location service, the system marks a copy of the location result to your application. In this way, your application will not consume extra power for obtaining the user location.|
S
shawn_he 已提交
1966 1967 1968 1969 1970 1971 1972 1973


## ReverseGeoCodeRequest

Defines a reverse geocoding request.

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

S
shawn_he 已提交
1974 1975 1976 1977
| 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.|
S
shawn_he 已提交
1978
| longitude | number | Yes| Yes| Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
S
shawn_he 已提交
1979
| maxItems | number | Yes| Yes| Maximum number of location records to be returned.|
S
shawn_he 已提交
1980 1981 1982 1983 1984 1985 1986 1987


## GeoCodeRequest

Defines a geocoding request.

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

S
shawn_he 已提交
1988 1989 1990 1991 1992 1993 1994 1995 1996
| 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.|
| minLatitude | number | Yes| Yes| Minimum latitude. This parameter is used with **minLongitude**, **maxLatitude**, and **maxLongitude** to specify the latitude and longitude ranges.|
| minLongitude | number | Yes| Yes| Minimum longitude.|
| maxLatitude | number | Yes| Yes| Maximum latitude.|
| maxLongitude | number | Yes| Yes| Maximum longitude.|
S
shawn_he 已提交
1997 1998 1999 2000 2001 2002 2003 2004


## GeoAddress

Defines a geographic location.

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

S
shawn_he 已提交
2005 2006 2007
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| latitude | number | Yes| No | Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
S
shawn_he 已提交
2008
| longitude | number | Yes| No | Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
S
shawn_he 已提交
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024
| 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.|
S
shawn_he 已提交
2025
| isFromMock | Boolean | Yes| No| Whether the geographic name is from the mock reverse geocoding function.|
S
shawn_he 已提交
2026 2027 2028 2029 2030 2031 2032 2033


## LocationRequest

Defines a location request.

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

S
shawn_he 已提交
2034 2035 2036 2037 2038 2039 2040
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request.|
| timeInterval | number | Yes| Yes| Time interval at which location information is reported.|
| distanceInterval | number | Yes| Yes| Distance interval at which location information is reported.|
| 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.|
S
shawn_he 已提交
2041 2042 2043 2044 2045 2046 2047 2048


## CurrentLocationRequest

Defines the current location request.

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

S
shawn_he 已提交
2049 2050 2051 2052 2053 2054
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request.|
| 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.|
| timeoutMs | number | Yes| Yes| Timeout duration, in milliseconds. The minimum value is **1000**.|
S
shawn_he 已提交
2055 2056 2057 2058 2059 2060 2061 2062


## SatelliteStatusInfo

Defines the satellite status information.

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

S
shawn_he 已提交
2063 2064 2065 2066 2067 2068 2069 2070
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| satellitesNumber | number | Yes| No| Number of satellites.|
| satelliteIds | Array<number> | Yes| No| Array of satellite IDs.|
| carrierToNoiseDensitys | Array<number> | Yes| No| Carrier-to-noise density ratio, that is, **cn0**.|
| altitudes | Array<number> | Yes| No| Altitude information.|
| azimuths | Array<number> | Yes| No| Azimuth information.|
| carrierFrequencies | Array<number> | Yes| No| Carrier frequency.|
S
shawn_he 已提交
2071 2072 2073 2074 2075 2076 2077 2078


## CachedGnssLocationsRequest

Represents a request for reporting cached GNSS locations.

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

S
shawn_he 已提交
2079 2080 2081 2082
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| reportingPeriodSec | number | Yes| Yes| Interval for reporting the cached GNSS locations, in milliseconds.|
| 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.|
S
shawn_he 已提交
2083 2084 2085 2086 2087 2088 2089 2090


## Geofence

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

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

S
shawn_he 已提交
2091 2092 2093 2094 2095 2096
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| latitude | number | Yes| Yes|Latitude information.|
| longitude | number | Yes|Yes| Longitude information.|
| radius | number | Yes|Yes| Radius of a circular geofence.|
| expiration | number | Yes|Yes| Expiration period of a geofence, in milliseconds.|
S
shawn_he 已提交
2097 2098 2099 2100 2101 2102 2103 2104


## GeofenceRequest

Represents a GNSS geofencing request.

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

S
shawn_he 已提交
2105 2106 2107 2108
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes |  Location scenario.|
| geofence |  [Geofence](#geofence)| Yes| Yes |  Geofence information.|
S
shawn_he 已提交
2109 2110 2111 2112 2113 2114 2115 2116


## LocationPrivacyType

Defines the privacy statement type.

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

S
shawn_he 已提交
2117 2118 2119 2120 2121
| Name| Value| Description|
| -------- | -------- | -------- |
| OTHERS | 0 | Other scenarios.|
| STARTUP | 1 | Privacy statement displayed in the startup wizard.|
| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.|
S
shawn_he 已提交
2122 2123 2124 2125 2126 2127 2128 2129


## LocationCommand

Defines an extended command.

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

S
shawn_he 已提交
2130 2131 2132 2133
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| scenario | [LocationRequestScenario](#locationrequestscenario)  | Yes| Yes | Location scenario.|
| command | string | Yes| Yes | Extended command, in the string format.|
S
shawn_he 已提交
2134 2135 2136 2137 2138 2139 2140 2141


## Location

Defines a location.

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

S
shawn_he 已提交
2142 2143 2144
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| latitude | number| Yes| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
S
shawn_he 已提交
2145
| longitude | number| Yes| No| Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
S
shawn_he 已提交
2146 2147 2148 2149 2150 2151 2152 2153 2154
| 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.|
| 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.|
| isFromMock | Boolean | Yes| No| Whether the location information is from the mock location function.|
S
shawn_he 已提交
2155 2156 2157 2158 2159 2160 2161 2162 2163 2164


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

S
shawn_he 已提交
2165 2166 2167
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| location |  [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Yes| Latitude and longitude information.|
S
shawn_he 已提交
2168
| geoAddress |  [GeoAddress](#geoaddress) | Yes| Yes|Geographic name.|
S
shawn_he 已提交
2169 2170 2171 2172 2173 2174 2175 2176 2177 2178


## LocationMockConfig

Represents the information of 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 已提交
2179 2180 2181 2182
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| timeInterval | number | Yes| Yes| Interval at which mock locations are reported, in seconds.|
| locations | Array&lt;Location&gt; | Yes| Yes| Array of mocked locations.|
S
shawn_he 已提交
2183 2184 2185 2186 2187 2188 2189 2190


## CountryCode

Represents country code information.

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

S
shawn_he 已提交
2191 2192 2193 2194
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| country | string | Yes| No| Country code.|
| type |  [CountryCodeType](#countrycodetype) | Yes| No| Country code source.|
S
shawn_he 已提交
2195 2196 2197 2198 2199 2200 2201 2202


## CountryCodeType

Represents the country code source type.

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

S
shawn_he 已提交
2203 2204 2205 2206 2207 2208
| 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.|