js-apis-geoLocationManager.md 49.0 KB
Newer Older
1
# @ohos.geoLocationManager (位置服务)
L
liu-binjun 已提交
2 3 4

位置服务提供GNSS定位、网络定位、地理编码、逆地理编码、国家码和地理围栏等基本功能。

5 6
> **说明:**
>
L
liu-binjun 已提交
7 8
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
## 申请权限

应用在使用系统能力前,需要检查是否已经获取用户授权访问设备位置信息。如未获得授权,可以向用户申请需要的位置权限,申请方式请参考下文。

系统提供的定位权限有:
- ohos.permission.LOCATION

- ohos.permission.APPROXIMATELY_LOCATION

- ohos.permission.LOCATION_IN_BACKGROUND

访问设备的位置信息,必须申请权限,并且获得用户授权。

API9之前的版本,申请ohos.permission.LOCATION即可。

API9及之后的版本,需要申请ohos.permission.APPROXIMATELY_LOCATION或者同时申请ohos.permission.APPROXIMATELY_LOCATION和ohos.permission.LOCATION;无法单独申请ohos.permission.LOCATION。

| 使用的API版本 | 申请位置权限 | 申请结果 | 位置的精确度 |
| -------- | -------- | -------- | -------- |
| 小于9 | ohos.permission.LOCATION | 成功 | 获取到精准位置,精准度在米级别。 |
| 大于等于9 | ohos.permission.LOCATION | 失败 | 无法获取位置。 |
| 大于等于9 | ohos.permission.APPROXIMATELY_LOCATION | 成功 | 获取到模糊位置,精确度为5公里。 |
| 大于等于9 | ohos.permission.APPROXIMATELY_LOCATION和ohos.permission.LOCATION | 成功 | 获取到精准位置,精准度在米级别。 |

如果应用在后台运行时也需要访问设备位置,除需要将应用声明为允许后台运行外,还必须申请ohos.permission.LOCATION_IN_BACKGROUND权限,这样应用在切入后台之后,系统可以继续上报位置信息。

开发者可以在应用配置文件中声明所需要的权限,具体可参考[授权申请指导](../../security/accesstoken-guidelines.md)

L
liu-binjun 已提交
37 38 39 40 41 42 43 44

## 导入模块

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


45
## geoLocationManager.on('countryCodeChange')
L
liu-binjun 已提交
46

47
on(type: 'countryCodeChange', callback: Callback<CountryCode>): void;
L
liu-binjun 已提交
48

49
订阅国家码信息变化事件。
L
liu-binjun 已提交
50 51 52 53 54 55 56

**系统能力**:SystemCapability.Location.Location.Core

**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
57 58
  | type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示订阅国家码信息变化事件。 |
  | callback | Callback<[CountryCode](#countrycode)> | 是 | 接收国家码信息上报。 |
L
liu-binjun 已提交
59 60 61 62 63 64 65 66 67

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
68
|3301500 | Failed to query the area information.                                       |
L
liu-binjun 已提交
69 70 71 72 73 74


**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
75 76 77 78
  var callback = (code) => {
      console.log('countryCodeChange: ' + JSON.stringify(code));
  }

79
  try {
80
      geoLocationManager.on('countryCodeChange', callback);
81 82
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
L
liu-binjun 已提交
83 84 85 86
  }
  ```


87
## geoLocationManager.off('countryCodeChange')
L
liu-binjun 已提交
88

89
off(type: 'countryCodeChange', callback?: Callback<CountryCode>): void;
L
liu-binjun 已提交
90

91
取消订阅国家码变化事件。
L
liu-binjun 已提交
92 93 94

**系统能力**:SystemCapability.Location.Location.Core

95
**参数**
L
liu-binjun 已提交
96 97 98

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
99 100
  | type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示取消订阅国家码信息变化事件。 |
  | callback | Callback<[CountryCode](#countrycode)> | 否 | 需要取消订阅的回调函数。若无此参数,则取消当前类型的所有订阅。 |
L
liu-binjun 已提交
101 102 103 104 105 106 107

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
108 109 110
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.                                                 |
|3301500 | Failed to query the area information.                                       |
L
liu-binjun 已提交
111 112 113 114 115

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
116 117 118
  var callback = (code) => {
      console.log('countryCodeChange: ' + JSON.stringify(code));
  }
119
  try {
120 121
      geoLocationManager.on('countryCodeChange', callback);
      geoLocationManager.off('countryCodeChange', callback);
122 123
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
L
liu-binjun 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
  }
  ```


## geoLocationManager.enableLocation

enableLocation(callback: AsyncCallback<void>): void;

打开位置服务,使用callback回调异步返回结果。

**系统API**:此接口为系统接口,三方应用不支持调用。

**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS

**系统能力**:SystemCapability.Location.Location.Core

**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback<void> | 是 | 用来接收错误码信息。 |

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  geoLocationManager.enableLocation((err, data) => {
      if (err) {
          console.log('enableLocation: err=' + JSON.stringify(err));
      }
  });
  ```


## geoLocationManager.enableLocation

enableLocation(): Promise<void>

打开位置服务,使用Promise方式异步返回结果。

**系统API**:此接口为系统接口,三方应用不支持调用。

**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS

**系统能力**:SystemCapability.Location.Location.Core

**返回值**

180 181 182
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | Promise<void>  | void | NA | 返回错误码信息。 |
L
liu-binjun 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
  geoLocationManager.enableLocation().then((result) => {
      console.log('promise, enableLocation succeed');
  })
  .catch((error) => {
      console.log('promise, enableLocation: error=' + JSON.stringify(error));
  });
  ```

## geoLocationManager.disableLocation

206
disableLocation(callback: AsyncCallback<void>): void;
L
liu-binjun 已提交
207

208
关闭位置服务,使用callback回调异步返回结果。
L
liu-binjun 已提交
209 210 211 212 213 214 215 216 217

**系统API**:此接口为系统接口,三方应用不支持调用。

**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS

**系统能力**:SystemCapability.Location.Location.Core

**参数**

218 219
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
220
  | callback | AsyncCallback<void> | 是 | 用来接收错误码的回调。 |
L
liu-binjun 已提交
221 222 223 224 225 226 227

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
228
|3301000 | Location service is unavailable.                                            |
L
liu-binjun 已提交
229 230 231 232 233

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
234 235 236 237 238 239 240 241 242
  try {
      geoLocationManager.disableLocation((err, data) => {
          if (err) {
              console.log('disableLocation: err=' + JSON.stringify(err));
          }
      });
  } catch (err) {
      console.error("errCode:" + err.code + ",errMessage:" + err.message);
  }
L
liu-binjun 已提交
243 244 245
  ```


246
## geoLocationManager.disableLocation
L
liu-binjun 已提交
247

248
disableLocation(): Promise<void>
L
liu-binjun 已提交
249

250
关闭位置服务,使用Promise方式异步返回结果。
L
liu-binjun 已提交
251

252
**系统API**:此接口为系统接口,三方应用不支持调用。
L
liu-binjun 已提交
253

254
**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
L
liu-binjun 已提交
255

256
**系统能力**:SystemCapability.Location.Location.Core
257 258 259

**返回值**

260 261
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
262
  | Promise<void> | void | NA |返回错误码。 |
L
liu-binjun 已提交
263 264 265 266 267 268 269

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
270
|3301000 | Location service is unavailable.                                            |
L
liu-binjun 已提交
271

272 273 274 275
**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
276 277
  geoLocationManager.disableLocation().then((result) => {
      console.log('promise, disableLocation succeed');
278 279
  })
  .catch((error) => {
280 281
      console.log('promise, disableLocation: error=' + JSON.stringify(error));
  });
282
  ```
L
liu-binjun 已提交
283 284


285
## geoLocationManager.isLocationPrivacyConfirmed
286

287
isLocationPrivacyConfirmed(type : LocationPrivacyType, callback: AsyncCallback<boolean>): void;
288

289
查询用户是否同意定位服务隐私申明,是否同意启用定位服务。只有系统应用才能调用。
290

291 292 293
**系统API**:此接口为系统接口,三方应用不支持调用。

**系统能力**:SystemCapability.Location.Location.Core
294 295 296 297 298

**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
299 300
  | type |  [LocationPrivacyType](#locationprivacytype)| 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
  | callback | AsyncCallback<boolean> | 是 | 表示用户是否同意定位服务隐私申明。 |
301 302 303 304 305 306 307

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
308
|3301000 | Location service is unavailable.                                            |
L
liu-binjun 已提交
309 310 311 312 313

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
314
  geoLocationManager.isLocationPrivacyConfirmed(1, (err, result) => {
L
liu-binjun 已提交
315
      if (err) {
316
          console.log('isLocationPrivacyConfirmed: err=' + JSON.stringify(err));
L
liu-binjun 已提交
317
      }
318 319
      if (result) {
          console.log('isLocationPrivacyConfirmed: result=' + JSON.stringify(result));
L
liu-binjun 已提交
320 321 322 323 324
      }
  });
  ```


325
## geoLocationManager.isLocationPrivacyConfirmed
L
liu-binjun 已提交
326

327
isLocationPrivacyConfirmed(type : LocationPrivacyType,): Promise<boolean>;
L
liu-binjun 已提交
328

329
查询用户是否同意定位服务隐私申明,是否同意启用定位服务。只有系统应用才能调用。
L
liu-binjun 已提交
330

331 332 333
**系统API**:此接口为系统接口,三方应用不支持调用。

**系统能力**:SystemCapability.Location.Location.Core
L
liu-binjun 已提交
334 335 336 337 338

**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
339
  | type | [LocationPrivacyType](#locationprivacytype) | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
L
liu-binjun 已提交
340

341
**返回值**
L
liu-binjun 已提交
342 343 344

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
345
  | Promise<boolean> |boolean| NA | 表示用户是否同意定位服务隐私申明。 |
L
liu-binjun 已提交
346 347 348 349 350 351 352

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
353
|3301000 | Location service is unavailable.                                            |
L
liu-binjun 已提交
354 355 356 357 358

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
359 360
  geoLocationManager.isLocationPrivacyConfirmed(1).then((result) => {
      console.log('promise, isLocationPrivacyConfirmed: ' + JSON.stringify(result));
L
liu-binjun 已提交
361 362 363 364
  });
  ```


365
## geoLocationManager.setLocationPrivacyConfirmStatus
L
liu-binjun 已提交
366

367
setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed: boolean, callback: AsyncCallback<void>): void;
L
liu-binjun 已提交
368

369
设置用户勾选定位服务隐私申明的状态,记录用户是否同意启用定位服务。只有系统应用才能调用。
L
liu-binjun 已提交
370

371
**系统API**:此接口为系统接口,三方应用不支持调用。
L
liu-binjun 已提交
372

373
**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
374

375
**系统能力**:SystemCapability.Location.Location.Core
L
liu-binjun 已提交
376 377 378 379 380

**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
381 382 383
  | type | [LocationPrivacyType](#locationprivacytype) | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
  | isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 |
  | callback | AsyncCallback<void> | 是 | 接收错误码信息。 |
384

385 386 387 388 389 390
**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
391
|3301000 | Location service is unavailable.                                            |
392

393 394 395 396
**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
397
  geoLocationManager.setLocationPrivacyConfirmStatus(1, true, (err, result) => {
398
      if (err) {
399
          console.log('setLocationPrivacyConfirmStatus: err=' + JSON.stringify(err));
400 401 402 403 404
      }
  });
  ```


405
## geoLocationManager.setLocationPrivacyConfirmStatus
406

407
setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolean): Promise<void>;
408

409
设置用户勾选定位服务隐私申明的状态,记录用户是否同意启用定位服务。只有系统应用才能调用。
410

411
**系统API**:此接口为系统接口,三方应用不支持调用。
412

413 414 415 416 417 418 419 420 421 422
**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS

**系统能力**:SystemCapability.Location.Location.Core

**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [LocationPrivacyType](#locationprivacytype) | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
  | isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 |
L
liu-binjun 已提交
423 424 425

**返回值**

426 427
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
428
  | Promise<void> |void|NA| 接收错误码。 |
L
liu-binjun 已提交
429 430 431 432 433 434 435

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
436
|3301000 | Location service is unavailable.                                            |
L
liu-binjun 已提交
437 438 439 440 441

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
442 443 444
  geoLocationManager.setLocationPrivacyConfirmStatus(1, true).then((result) => {
      console.log('promise, setLocationPrivacyConfirmStatus succeed');
  })
L
liu-binjun 已提交
445
  .catch((error) => {
446
      console.log('promise, disableLocation: error=' + JSON.stringify(error));
L
liu-binjun 已提交
447 448 449 450
  });
  ```


451
## geoLocationManager.getCountryCode
L
liu-binjun 已提交
452

453
getCountryCode(callback: AsyncCallback<CountryCode>): void;
L
liu-binjun 已提交
454

455
查询当前的国家码。
456

457
**系统能力**:SystemCapability.Location.Location.Core
L
liu-binjun 已提交
458 459 460 461 462

**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
463
  | callback | AsyncCallback<[CountryCode](#countrycode)> | 是 | 用来接收国家码。 |
L
liu-binjun 已提交
464 465 466 467 468 469 470

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
471 472
|3301000 | Location service is unavailable.                                            |
|3301500 | Failed to query the area information.|
L
liu-binjun 已提交
473 474 475 476 477

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
478
  geoLocationManager.getCountryCode((err, result) => {
L
liu-binjun 已提交
479
      if (err) {
480 481 482 483
          console.log('getCountryCode: err=' + JSON.stringify(err));
      }
      if (result) {
          console.log('getCountryCode: result=' + JSON.stringify(result));
L
liu-binjun 已提交
484 485 486 487 488
      }
  });
  ```


489
## geoLocationManager.getCountryCode
L
liu-binjun 已提交
490

491
getCountryCode(): Promise<CountryCode>;
L
liu-binjun 已提交
492

493
查询当前的国家码。
L
liu-binjun 已提交
494

495
**系统能力**:SystemCapability.Location.Location.Core
L
liu-binjun 已提交
496 497 498

**返回值**

499 500
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
501
  | Promise<[CountryCode](#countrycode)> | [CountryCode](#countrycode) | NA | 用来接收国家码。 |
L
liu-binjun 已提交
502 503 504 505 506 507 508

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
509 510
|3301000 | Location service is unavailable.                                            |
|3301500 | Failed to query the area information.|
L
liu-binjun 已提交
511 512 513 514 515

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
516 517 518
  geoLocationManager.getCountryCode()
  .then((result) => {
      console.log('promise, getCountryCode: result=' + JSON.stringify(result));
L
liu-binjun 已提交
519 520
  })
  .catch((error) => {
521
      console.log('promise, getCountryCode: error=' + JSON.stringify(error));
L
liu-binjun 已提交
522 523 524 525
  });
  ```


526
## geoLocationManager.enableLocationMock
L
liu-binjun 已提交
527

528
enableLocationMock(callback: AsyncCallback<void>): void;
L
liu-binjun 已提交
529

530
使能位置模拟功能。
L
liu-binjun 已提交
531 532 533

**系统能力**:SystemCapability.Location.Location.Core

534 535
**系统API**:此接口为系统接口,三方应用不支持调用。

L
liu-binjun 已提交
536 537 538 539
**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
540
  | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
L
liu-binjun 已提交
541 542 543 544 545 546 547

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
548 549
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.|
L
liu-binjun 已提交
550 551 552 553 554

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
555
  geoLocationManager.enableLocationMock((err, result) => {
L
liu-binjun 已提交
556
      if (err) {
557
          console.log('enableLocationMock: err=' + JSON.stringify(err));
L
liu-binjun 已提交
558 559 560 561
      }
  });
  ```

562
## geoLocationManager.enableLocationMock
L
liu-binjun 已提交
563

564
enableLocationMock(): Promise<void>;
L
liu-binjun 已提交
565

566
使能位置模拟功能。
L
liu-binjun 已提交
567 568 569

**系统能力**:SystemCapability.Location.Location.Core

570
**系统API**:此接口为系统接口,三方应用不支持调用。
L
liu-binjun 已提交
571 572 573

**返回值**

574 575
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
576
  | Promise<void> | void|NA|用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。  |
L
liu-binjun 已提交
577 578 579 580 581 582 583 584

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
585
|3301100 | The location switch is off.|
L
liu-binjun 已提交
586 587 588 589 590

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
591 592 593 594
  geoLocationManager.enableLocationMock()
  .then((result) => {
      console.log('promise, enableLocationMock: succeed');
  })
L
liu-binjun 已提交
595
  .catch((error) => {
596 597 598
      if (error) {
        console.log('promise, enableLocationMock: error=' + JSON.stringify(error));
      }
L
liu-binjun 已提交
599 600 601 602
  });
  ```


603
## geoLocationManager.disableLocationMock
L
liu-binjun 已提交
604

605
disableLocationMock(callback: AsyncCallback<void>): void;
L
liu-binjun 已提交
606

607
去使能位置模拟功能。
L
liu-binjun 已提交
608 609 610

**系统能力**:SystemCapability.Location.Location.Core

611 612
**系统API**:此接口为系统接口,三方应用不支持调用。

L
liu-binjun 已提交
613 614 615 616
**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
617
  | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
L
liu-binjun 已提交
618 619 620 621 622 623 624 625

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
626
|3301100 | The location switch is off.|
L
liu-binjun 已提交
627 628 629 630 631

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
632
  geoLocationManager.disableLocationMock((err, result) => {
L
liu-binjun 已提交
633
      if (err) {
634
          console.log('disableLocationMock: err=' + JSON.stringify(err));
L
liu-binjun 已提交
635 636 637 638 639
      }
  });
  ```


640
## geoLocationManager.disableLocationMock
L
liu-binjun 已提交
641

642
disableLocationMock(): Promise<void>;
L
liu-binjun 已提交
643

644
去使能位置模拟功能。
L
liu-binjun 已提交
645 646 647

**系统能力**:SystemCapability.Location.Location.Core

648 649
**系统API**:此接口为系统接口,三方应用不支持调用。

L
liu-binjun 已提交
650 651
**返回值**

652 653
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
654
  | Promise<void> |void|NA| 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。  |
L
liu-binjun 已提交
655 656 657 658 659 660 661 662

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
663
|3301100 | The location switch is off.|
L
liu-binjun 已提交
664 665 666 667 668

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
669
  geoLocationManager.disableLocationMock()
L
liu-binjun 已提交
670
  .then((result) => {
671
        console.log('promise, disableLocationMock succeed');
L
liu-binjun 已提交
672 673
  })
  .catch((error) => {
674 675 676
      if (error) {
        console.log('promise, disableLocationMock: error=' + JSON.stringify(error));
      }
L
liu-binjun 已提交
677 678 679 680
  });
  ```


681
## geoLocationManager.setMockedLocations
L
liu-binjun 已提交
682

683
setMockedLocations(config: LocationMockConfig, callback: AsyncCallback<void>): void;
L
liu-binjun 已提交
684

685
设置模拟的位置信息,后面会以该接口中携带的时间间隔上报模拟位置。
L
liu-binjun 已提交
686 687 688 689 690

**系统能力**:SystemCapability.Location.Location.Core

**系统API**:此接口为系统接口,三方应用不支持调用。

691 692 693 694 695 696 697
**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | config |  [LocationMockConfig](#locationmockconfig) | 是 | 指示位置模拟的配置参数,包含模拟位置上报的时间间隔和模拟位置数组。 |
  | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |

L
liu-binjun 已提交
698 699 700 701 702 703 704 705 706 707 708 709 710
**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.|

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
711 712 713 714 715 716 717 718 719 720 721 722 723
  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};
  geoLocationManager.setMockedLocations(config, (err, data) => {
      if (err) {
          console.log('setMockedLocations: err=' + JSON.stringify(err));
      }
  });
L
liu-binjun 已提交
724 725
  ```

726
## geoLocationManager.setMockedLocations
L
liu-binjun 已提交
727

728
setMockedLocations(config: LocationMockConfig): Promise<void>;
L
liu-binjun 已提交
729

730
设置模拟的位置信息,后面会以该接口中携带的时间间隔上报模拟位置。
L
liu-binjun 已提交
731 732 733 734 735

**系统能力**:SystemCapability.Location.Location.Core

**系统API**:此接口为系统接口,三方应用不支持调用。

736 737 738 739 740 741 742 743 744 745 746 747
**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | config | [LocationMockConfig](#locationmockconfig) | 是 | 指示位置模拟的配置参数,包含模拟位置上报的时间间隔和模拟位置数组。 |

**返回值**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | Promise<void> |void|NA| 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。  |

L
liu-binjun 已提交
748 749 750 751 752 753 754 755 756 757 758 759 760
**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |
|3301100 | The location switch is off.|

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
  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};
  geoLocationManager.setMockedLocations(config)
  .then((result) => {
      console.log('promise, setMockedLocations succeed');
  })
  .catch((error) => {
      if (error) {
        console.log('promise, setMockedLocations: error=' + JSON.stringify(error));
      }
  });
L
liu-binjun 已提交
778 779 780
  ```


781
## geoLocationManager.enableReverseGeocodingMock
L
liu-binjun 已提交
782

783
enableReverseGeocodingMock(callback: AsyncCallback<void>): void;
L
liu-binjun 已提交
784

785
使能逆地理编码模拟功能。
L
liu-binjun 已提交
786 787 788 789 790 791 792 793 794

**系统能力**:SystemCapability.Location.Location.Core

**系统API**:此接口为系统接口,三方应用不支持调用。

**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
795
  | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
L
liu-binjun 已提交
796 797 798 799 800 801 802 803 804 805 806 807 808

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
809 810 811 812 813
  geoLocationManager.enableReverseGeocodingMock((err, data) => {
      if (err) {
          console.log('enableReverseGeocodingMock: err=' + JSON.stringify(err));
      }
  });
L
liu-binjun 已提交
814 815 816 817 818
  ```


## geoLocationManager.enableReverseGeocodingMock

819
enableReverseGeocodingMock(): Promise<void>;
L
liu-binjun 已提交
820 821 822 823 824 825 826

使能逆地理编码模拟功能。

**系统能力**:SystemCapability.Location.Location.Core

**系统API**:此接口为系统接口,三方应用不支持调用。

827 828 829 830 831 832
**返回值**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | Promise<void> | void|NA|用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。  |

L
liu-binjun 已提交
833 834 835 836 837 838 839 840 841 842 843 844
**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
845 846 847 848 849 850 851 852 853
  geoLocationManager.enableReverseGeocodingMock()
  .then((result) => {
      console.log('promise, enableReverseGeocodingMock succeed');
  })
  .catch((error) => {
      if (error) {
        console.log('promise, enableReverseGeocodingMock: error=' + JSON.stringify(error));
      }
  });
L
liu-binjun 已提交
854 855 856 857 858
  ```


## geoLocationManager.disableReverseGeocodingMock

859
disableReverseGeocodingMock(callback: AsyncCallback<void>): void;
L
liu-binjun 已提交
860 861 862 863 864 865 866

去使能逆地理编码模拟功能。

**系统能力**:SystemCapability.Location.Location.Core

**系统API**:此接口为系统接口,三方应用不支持调用。

867 868 869 870 871 872
**参数**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |

L
liu-binjun 已提交
873 874 875 876 877 878 879 880 881 882 883 884
**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
885 886 887 888 889
  geoLocationManager.disableReverseGeocodingMock((err, result) => {
      if (err) {
          console.log('disableReverseGeocodingMock: err=' + JSON.stringify(err));
      }
  });
L
liu-binjun 已提交
890 891 892
  ```


893
## geoLocationManager.disableReverseGeocodingMock
L
liu-binjun 已提交
894

895
disableReverseGeocodingMock(): Promise<void>;
L
liu-binjun 已提交
896

897
去使能逆地理编码模拟功能。
L
liu-binjun 已提交
898 899 900 901 902

**系统能力**:SystemCapability.Location.Location.Core

**系统API**:此接口为系统接口,三方应用不支持调用。

903
**返回值**
L
liu-binjun 已提交
904

905 906
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
907
  | Promise<void> |void|NA| 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。  |
L
liu-binjun 已提交
908 909 910 911 912 913 914 915 916 917 918 919 920

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
921 922 923 924 925 926 927 928 929
  geoLocationManager.disableReverseGeocodingMock()
  .then((result) => {
      console.log('promise, disableReverseGeocodingMock succeed');
  })
  .catch((error) => {
      if (error) {
        console.log('promise, disableReverseGeocodingMock: error=' + JSON.stringify(error));
      }
  });
L
liu-binjun 已提交
930 931 932
  ```


933
## geoLocationManager.setReverseGeocodingMockInfo
L
liu-binjun 已提交
934

935
setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>, callback: AsyncCallback<void>): void;
L
liu-binjun 已提交
936

937
设置逆地理编码模拟功能的配置信息,包含了位置和地名的对应关系,后续进行逆地理编码查询时如果位置信息位于配置信息中,就返回对应的地名。
L
liu-binjun 已提交
938

939 940
**系统能力**:SystemCapability.Location.Location.Core

941
**系统API**:此接口为系统接口,三方应用不支持调用。
942

943
**参数**
944

945 946
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
947 948
  | mockInfos | Array<[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)> | 是 | 指示逆地理编码模拟功能的配置参数数组。逆地理编码模拟功能的配置参数包含了一个位置和一个地名。 |
  | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
L
liu-binjun 已提交
949 950 951 952 953 954 955 956 957 958 959 960 961

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
962 963 964 965 966 967 968 969 970 971 972 973
  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}},
  ];
  geoLocationManager.setReverseGeocodingMockInfo(mockInfos, (err, data) => {
      if (err) {
          console.log('promise, setReverseGeocodingMockInfo, err:' + JSON.stringify(err));
      }
  });
L
liu-binjun 已提交
974 975 976
  ```


977
## geoLocationManager.setReverseGeocodingMockInfo
L
liu-binjun 已提交
978

979
setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>): Promise<void>;
L
liu-binjun 已提交
980

981 982 983
设置逆地理编码模拟功能的配置信息,包含了位置和地名的对应关系,后续进行逆地理编码查询时如果位置信息位于配置信息中,就返回对应的地名。

**系统能力**:SystemCapability.Location.Location.Core
L
liu-binjun 已提交
984 985 986

**系统API**:此接口为系统接口,三方应用不支持调用。

987
**参数**
988

989 990 991
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | mockInfos | Array<[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)> | 是 | 指示逆地理编码模拟功能的配置信息数组。逆地理编码模拟功能的配置信息包含了一个位置和一个地名。 |
992

993
**返回值**
L
liu-binjun 已提交
994 995 996

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
997
  | Promise<void> | void | NA | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。  |
L
liu-binjun 已提交
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010

**错误码**

以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable.                                            |

**示例**
  
  ```ts
  import geoLocationManager from '@ohos.geoLocationManager';
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
  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}},
  ];
  geoLocationManager.setReverseGeocodingMockInfo(mockInfos)
  .then((result) => {
      console.log('promise, setReverseGeocodingMockInfo succeed');
  })
  .catch((error) => {
      if (error) {
        console.log('promise, setReverseGeocodingMockInfo: error=' + JSON.stringify(error));
      }
  });
L
liu-binjun 已提交
1027 1028 1029 1030 1031 1032 1033 1034 1035
  ```


## LocationRequestPriority

位置请求中位置信息优先级设置。

**系统能力**:SystemCapability.Location.Location.Core

1036
| 名称 | 值 | 说明 |
L
liu-binjun 已提交
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
| -------- | -------- | -------- |
| UNSET | 0x200 | 表示未设置优先级。 |
| ACCURACY | 0x201 | 表示精度优先。 |
| LOW_POWER | 0x202 | 表示低功耗优先。 |
| FIRST_FIX | 0x203 | 表示快速获取位置优先,如果应用希望快速拿到1个位置,可以将优先级设置为该字段。 |


## LocationRequestScenario

  位置请求中定位场景设置。

**系统能力**:SystemCapability.Location.Location.Core

1050
| 名称 | 值 | 说明 |
L
liu-binjun 已提交
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
| -------- | -------- | -------- |
| UNSET | 0x300 | 表示未设置场景信息。 |
| NAVIGATION | 0x301 | 表示导航场景。 |
| TRAJECTORY_TRACKING | 0x302 | 表示运动轨迹记录场景。 |
| CAR_HAILING | 0x303 | 表示打车场景。 |
| DAILY_LIFE_SERVICE | 0x304 | 表示日常服务使用场景。 |
| NO_POWER | 0x305 | 表示无功耗功场景,这种场景下不会主动触发定位,会在其他应用定位时,才给当前应用返回位置。 |


## ReverseGeoCodeRequest

逆地理编码请求接口。

**系统能力**:SystemCapability.Location.Location.Geocoder

1066
| 名称 | 类型 | 可读 | 可写 | 说明 |
1067
| -------- | -------- | -------- | -------- | -------- |
1068 1069 1070 1071
| locale | string | 是 | 是 | 指定位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| latitude | number | 是 | 是 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude | number | 是 | 是 | 表示经度信息,正值表示东经,负值表示西经。 |
| maxItems | number | 是 | 是 | 指定返回位置信息的最大个数。 |
L
liu-binjun 已提交
1072 1073 1074 1075 1076 1077 1078 1079


## GeoCodeRequest

地理编码请求接口。

**系统能力**:SystemCapability.Location.Location.Geocoder

1080
| 名称 | 类型 | 可读|可写 | 说明 |
1081
| -------- | -------- | -------- | -------- | -------- |
1082
| locale | string | 是 | 是 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
1083
| description | string | 是 | 是 | 表示位置信息描述,如“上海市浦东新区xx路xx号”。 |
1084 1085 1086 1087 1088
| maxItems | number | 是 | 是 | 表示返回位置信息的最大个数。 |
| minLatitude | number | 是 | 是 | 表示最小纬度信息,与下面三个参数一起,表示一个经纬度范围。 |
| minLongitude | number | 是 | 是 | 表示最小经度信息。 |
| maxLatitude | number | 是 | 是 | 表示最大纬度信息。 |
| maxLongitude | number | 是 | 是 | 表示最大经度信息。 |
L
liu-binjun 已提交
1089 1090 1091 1092 1093 1094 1095 1096


## GeoAddress

地理编码类型。

**系统能力**:SystemCapability.Location.Location.Geocoder

1097
| 名称 | 类型 | 可读|可写 | 说明 |
1098
| -------- | -------- | -------- | -------- | -------- |
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
| latitude | number | 是 | 否  | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude | number | 是 | 否  | 表示经度信息,正值表示东经,负值表是西经。 |
| locale | string | 是 | 否  | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| placeName | string | 是 | 否  | 表示地区信息。 |
| countryCode | string | 是 | 否  | 表示国家码信息。 |
| countryName | string| 是 | 否 | 表示国家信息。 |
| administrativeArea | string | 是 | 否 | 表示省份区域信息。 |
| subAdministrativeArea | string | 是 | 否 | 表示表示子区域信息。 |
| locality | string | 是 | 否 | 表示城市信息。 |
| subLocality | string | 是 | 否 | 表示子城市信息。 |
| roadName | string | 是 | 否 |表示路名信息。 |
| subRoadName | string | 是 | 否 | 表示子路名信息。 |
| premises | string| 是 | 否|表示门牌号信息。 |
| postalCode | string | 是 | 否 | 表示邮政编码信息。 |
| phoneNumber | string | 是 | 否 | 表示联系方式信息。 |
| addressUrl | string | 是 | 否 | 表示位置信息附件的网址信息。 |
| descriptions | Array<string> | 是 | 否 | 表示附加的描述信息。 |
| descriptionsSize | number | 是 | 否 | 表示附加的描述信息数量。 |
| isFromMock | Boolean | 是 | 否 | 表示地名信息是否来自于逆地理编码模拟功能。 |
L
liu-binjun 已提交
1118 1119 1120 1121 1122 1123 1124 1125


## LocationRequest

位置信息请求类型。

**系统能力**:SystemCapability.Location.Location.Core

1126
| 名称 | 类型 | 可读|可写 | 说明 |
1127
| -------- | -------- | -------- | -------- | -------- |
1128 1129 1130 1131 1132
| priority | [LocationRequestPriority](#locationrequestpriority) | 是 | 是 | 表示优先级信息。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 是 | 是 | 表示场景信息。 |
| timeInterval | number | 是 | 是 | 表示上报位置信息的时间间隔。 |
| distanceInterval | number | 是 | 是 | 表示上报位置信息的距离间隔。 |
| maxAccuracy | number | 是 | 是 | 表示精度信息。仅在精确位置功能场景下有效,模糊位置功能生效场景下该字段无意义。 |
L
liu-binjun 已提交
1133 1134 1135 1136 1137 1138 1139 1140


## CurrentLocationRequest

当前位置信息请求类型。

**系统能力**:SystemCapability.Location.Location.Core

1141
| 名称 | 类型 | 可读|可写 | 说明 |
1142
| -------- | -------- | -------- | -------- | -------- |
1143 1144 1145 1146
| priority | [LocationRequestPriority](#locationrequestpriority) | 是 | 是 | 表示优先级信息。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 是 | 是 | 表示场景信息。 |
| maxAccuracy | number | 是 | 是| 表示精度信息,单位是米。仅在精确位置功能场景下有效,模糊位置功能生效场景下该字段无意义。 |
| timeoutMs | number | 是 | 是 | 表示超时时间,单位是毫秒,最小为1000毫秒。 |
L
liu-binjun 已提交
1147 1148 1149 1150 1151 1152 1153 1154


## SatelliteStatusInfo

卫星状态信息。

**系统能力**:SystemCapability.Location.Location.Gnss

1155
| 名称 | 类型 | 可读|可写 | 说明 |
1156
| -------- | -------- | -------- | -------- | -------- |
1157 1158 1159 1160 1161 1162
| satellitesNumber | number | 是 | 否 | 表示卫星个数。 |
| satelliteIds | Array<number> | 是 | 否 | 表示每个卫星的ID,数组类型。 |
| carrierToNoiseDensitys | Array<number> | 是 | 否 | 表示载波噪声功率谱密度比,即cn0。 |
| altitudes | Array<number> | 是 | 否 | 表示高程信息。 |
| azimuths | Array<number> | 是 | 否 | 表示方位角。 |
| carrierFrequencies | Array<number> | 是 | 否 | 表示载波频率。 |
L
liu-binjun 已提交
1163 1164 1165 1166 1167 1168 1169 1170


## CachedGnssLocationsRequest

请求订阅GNSS缓存位置上报功能接口的配置参数。

**系统能力**:SystemCapability.Location.Location.Gnss

1171
| 名称 | 类型 | 可读|可写 | 说明 |
1172
| -------- | -------- | -------- | -------- | -------- |
1173 1174
| reportingPeriodSec | number | 是 | 是 | 表示GNSS缓存位置上报的周期,单位是毫秒。 |
| wakeUpCacheQueueFull | boolean | 是 | 是  | true表示GNSS芯片底层缓存队列满之后会主动唤醒AP芯片,并把缓存位置上报给应用。<br/>false表示GNSS芯片底层缓存队列满之后不会主动唤醒AP芯片,会把缓存位置直接丢弃。 |
L
liu-binjun 已提交
1175 1176 1177 1178 1179 1180 1181 1182


## Geofence

GNSS围栏的配置参数。目前只支持圆形围栏。

**系统能力**:SystemCapability.Location.Location.Geofence

1183 1184 1185 1186 1187 1188
| 名称 | 类型 | 可读|可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| latitude | number | 是 | 是 |表示纬度。 |
| longitude | number | 是 |是 | 表示经度。 |
| radius | number | 是 |是 | 表示圆形围栏的半径。 |
| expiration | number | 是 |是 | 围栏存活的时间,单位是毫秒。 |
L
liu-binjun 已提交
1189 1190 1191 1192 1193 1194 1195 1196


## GeofenceRequest

请求添加GNSS围栏消息中携带的参数,包括定位优先级、定位场景和围栏信息。

**系统能力**:SystemCapability.Location.Location.Geofence

1197
| 名称 | 类型 | 可读|可写 | 说明 |
1198
| -------- | -------- | -------- | -------- | -------- |
1199 1200 1201
| priority | [LocationRequestPriority](#locationrequestpriority) | 是 | 是  | 表示位置信息优先级。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 是 | 是  | 表示定位场景。 |
| geofence |  [Geofence](#geofence) | 是 | 是  | 表示围栏信息。 |
L
liu-binjun 已提交
1202 1203 1204 1205 1206 1207 1208 1209


## LocationPrivacyType

定位服务隐私协议类型。

**系统能力**:SystemCapability.Location.Location.Core

1210
| 名称 | 值 | 说明 |
L
liu-binjun 已提交
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222
| -------- | -------- | -------- |
| OTHERS | 0 | 其他场景。 |
| STARTUP | 1 | 开机向导场景下的隐私协议。 |
| CORE_LOCATION | 2 | 开启网络定位时弹出的隐私协议。 |


## LocationCommand

扩展命令结构体。

**系统能力**:SystemCapability.Location.Location.Core

1223
| 名称 | 类型 | 可读|可写 | 说明 |
1224
| -------- | -------- | -------- | -------- | -------- |
1225 1226
| scenario | [LocationRequestScenario](#locationrequestscenario)  | 是 | 是  | 表示定位场景。 |
| command | string | 是 | 是  | 扩展命令字符串。 |
L
liu-binjun 已提交
1227 1228 1229 1230 1231 1232 1233 1234


## Location

位置信息类型。

**系统能力**:SystemCapability.Location.Location.Core

1235
| 名称 | 类型 | 可读|可写 | 说明 |
1236
| -------- | -------- | -------- | -------- | -------- |
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
| latitude | number| 是 | 否 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude | number| 是 | 否 | 表示经度信息,正值表示东经,负值表是西经。 |
| altitude | number | 是 | 否 | 表示高度信息,单位米。 |
| accuracy | number | 是 | 否 | 表示精度信息,单位米。 |
| speed | number | 是 | 否 |表示速度信息,单位米每秒。 |
| timeStamp | number | 是 | 否 | 表示位置时间戳,UTC格式。 |
| direction | number | 是 | 否 | 表示航向信息。 |
| timeSinceBoot | number | 是 | 否 | 表示位置时间戳,开机时间格式。 |
| additions | Array&lt;string&gt; | 是 | 否 | 附加信息。 |
| additionSize | number | 是 | 否 | 附加信息数量。 |
| isFromMock | Boolean | 是 | 否 | 表示位置信息是否来自于位置模拟功能。 |
L
liu-binjun 已提交
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257


## ReverseGeocodingMockInfo

逆地理编码模拟功能的配置信息,包含一个位置信息和一个地名信息。

**系统能力**:SystemCapability.Location.Location.Core

**系统API**:此接口为系统接口,三方应用不支持调用。

1258
| 名称 | 类型 | 可读|可写 | 说明 |
1259
| -------- | -------- | -------- | -------- | -------- |
1260 1261
| location |  [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 是 | 表示经纬度信息。 |
| geoAddress |  [GeoAddress](#geoaddress) | 是 | 是 |表示地名信息。 |
L
liu-binjun 已提交
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271


## LocationMockConfig

位置模拟功能的配置参数,包含了模拟位置上报的时间间隔和模拟位置数组。

**系统能力**:SystemCapability.Location.Location.Core

**系统API**:此接口为系统接口,三方应用不支持调用。

1272
| 名称 | 类型 | 可读|可写 | 说明 |
1273
| -------- | -------- | -------- | -------- | -------- |
1274 1275
| timeInterval | number | 是 | 是 | 表示模拟位置上报的时间间隔,单位是秒。 |
| locations | Array&lt;Location&gt; | 是 | 是 | 表示模拟位置数组。 |
L
liu-binjun 已提交
1276 1277 1278 1279 1280 1281 1282 1283


## CountryCode

国家码信息结构体,包含国家码字符串和国家码的来源信息。

**系统能力**:SystemCapability.Location.Location.Core

1284
| 名称 | 类型 | 可读|可写 | 说明 |
1285
| -------- | -------- | -------- | -------- | -------- |
1286 1287
| country | string | 是 | 否 | 表示国家码字符串。 |
| type |  [CountryCodeType](#countrycodetype) | 是 | 否 | 表示国家码信息来源。 |
L
liu-binjun 已提交
1288 1289 1290 1291 1292 1293 1294 1295


## CountryCodeType

国家码来源类型。

**系统能力**:SystemCapability.Location.Location.Core

1296
| 名称 | 值 | 说明 |
L
liu-binjun 已提交
1297 1298 1299 1300 1301
| -------- | -------- | -------- |
| COUNTRY_CODE_FROM_LOCALE | 1 | 从全球化模块的语言配置信息中获取到的国家码。 |
| COUNTRY_CODE_FROM_SIM | 2 | 从SIM卡中获取到的国家码。 |
| COUNTRY_CODE_FROM_LOCATION | 3 | 基于用户的位置信息,通过逆地理编码查询到的国家码。 |
| COUNTRY_CODE_FROM_NETWORK | 4 | 从蜂窝网络注册信息中获取到的国家码。 |