1# @ohos.geoLocationManager (Geolocation Manager) (System API)
2
3The **geoLocationManager** module provides location services such as Global Navigation Satellite System (GNSS)-based positioning, network positioning, geofencing, as well as geocoding and reverse geocoding.
4
5> **NOTE**
6>
7> 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.
8> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.geoLocationManager (Geolocation Manager)](js-apis-geoLocationManager.md).
9> This module supports only the WGS-84 coordinate system.
10
11## Applying for Permissions
12
13Before 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.
14
15The system provides the following location permissions:
16- ohos.permission.LOCATION
17
18- ohos.permission.APPROXIMATELY_LOCATION
19
20- ohos.permission.LOCATION_IN_BACKGROUND
21
22If your application needs to access the device location information, it must first apply for required permissions. Specifically speaking:
23
24API versions earlier than 9: Apply for **ohos.permission.LOCATION**.
25
26API 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.
27
28| API Version| Location Permission| Permission Application Result| Location Accuracy|
29| -------- | -------- | -------- | -------- |
30| Earlier than 9| ohos.permission.LOCATION | Success| Location accurate to meters|
31| 9 and later| ohos.permission.LOCATION | Failure| No location obtained|
32| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers|
33| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters|
34
35To access the device location information when running in the background, an application needs to request for a continuous task of the LOCATION type. In this way, the system continues to report device location information after your application moves to the background. For details about how to request for a continuous task, see [Continuous Task](../../task-management/continuous-task.md).
36
37A user can grant the **ohos.permission.LOCATION_IN_BACKGROUND** permission for an application on the setting page. For details, see [ohos.permission.LOCATION_IN_BACKGROUND](../../security/AccessToken/permissions-for-all.md#ohospermissionlocation_in_background).
38
39You can declare the required permission in your application's configuration file. For details, see [Requesting User Authorization](../../security/AccessToken/request-user-authorization.md).
40
41
42## Modules to Import
43
44```ts
45import { geoLocationManager } from '@kit.LocationKit';
46```
47
48## GeoAddress
49
50Geocoding address information.
51
52**System capability**: SystemCapability.Location.Location.Geocoder
53
54| Name| Type| Read Only| Optional| Description|
55| -------- | -------- | -------- | -------- | -------- |
56| isFromMock | Boolean | No| Yes| **true**: The geographic address is obtained from the mock reverse geocoding function.<br>**false**: The geographic address is not obtained from the mock reverse geocoding function.<br>**System API**: This is a system API.|
57
58
59## Location
60
61Location information.
62
63**System capability**: SystemCapability.Location.Location.Core
64
65| Name| Type| Read Only| Optional| Description|
66| -------- | -------- | -------- | -------- | -------- |
67| isFromMock | Boolean | No| Yes| **true**: The location information is obtained from the mock location function.<br>**false**: The location information is not obtained from the location simulation function.<br>**System API**: This is a system API.|
68
69
70## ReverseGeocodingMockInfo
71
72Defines the configuration of the mock reverse geocoding function.
73
74**System capability**: SystemCapability.Location.Location.Core
75
76**System API**: This is a system API.
77
78| Name| Type| Read Only| Optional| Description|
79| -------- | -------- | -------- | -------- | -------- |
80| location |  [ReverseGeoCodeRequest](js-apis-geoLocationManager.md#reversegeocoderequest) | No| No| Latitude and longitude information.|
81| geoAddress |  [GeoAddress](#geoaddress) | No| No|Geographical name.|
82
83
84## LocationMockConfig
85
86Defines the configuration of the mock location function.
87
88**System capability**: SystemCapability.Location.Location.Core
89
90**System API**: This is a system API.
91
92| Name| Type| Read Only| Optional| Description|
93| -------- | -------- | -------- | -------- | -------- |
94| timeInterval | number | No| No| Time interval at which mock locations are reported, in seconds.|
95| locations | Array&lt;[Location](#location)&gt; | No| No| Array of mocked locations.|
96
97## LocatingRequiredDataConfig<sup>10+</sup>
98
99Defines the configuration for obtaining the required data of the location service.
100
101**System capability**: SystemCapability.Location.Location.Core
102
103**System API**: This is a system API.
104
105| Name| Type| Read Only| Optional| Description|
106| -------- | -------- | -------- | -------- | -------- |
107| type | [LocatingRequiredDataType](#locatingrequireddatatype10) | No| No| Type of the required data.|
108| needStartScan |  boolean | No| No| **true**: Scanning needs to be initiated.<br>**false**: Scanning does not need to be initiated.|
109| scanInterval |  number | No| Yes| Scanning interval, in milliseconds. The specified value must be greater than **0**. The default value is **10000**.|
110| scanTimeout |  number | No| Yes| Scanning timeout interval, in milliseconds. The value ranges from **0** to **600000**. The default value is **10000**.|
111
112
113## LocatingRequiredData<sup>10+</sup>
114
115Defines the required data of the location service, including the Wi-Fi or Bluetooth scanning result. After obtaining the data, an application can use the data for services such as network positioning.
116
117**System capability**: SystemCapability.Location.Location.Core
118
119**System API**: This is a system API.
120
121| Name| Type| Read Only| Optional| Description|
122| -------- | -------- | -------- | -------- | -------- |
123| wifiData | [WifiScanInfo](#wifiscaninfo10) | No| Yes| Wi-Fi scanning result.|
124| bluetoothData |  [BluetoothScanInfo](#bluetoothscaninfo10) | No| Yes| Bluetooth scanning result.|
125
126
127## WifiScanInfo<sup>10+</sup>
128
129Defines the Wi-Fi scanning information, including the SSID, BSSID, and RSSI of the scanned Wi-Fi hotspot.
130
131**System capability**: SystemCapability.Location.Location.Core
132
133**System API**: This is a system API.
134
135| Name| Type| Read Only| Optional| Description|
136| -------- | -------- | -------- | -------- | -------- |
137| ssid | string | No| No| Service set identifier (SSID) of a Wi-Fi hotspot, in UTF-8 format.|
138| bssid | string | No| No| Base station subsystem identifier (BSSID) of a Wi-Fi hotspot.|
139| rssi | number | No| No| Received signal strength indicator (RSSI) of a Wi-Fi hotspot, in dBm.|
140| frequency | number | No| No| Frequency of a Wi-Fi hotspot.|
141| timestamp | number | No| No| Scanning timestamp.|
142
143
144## BluetoothScanInfo<sup>10+</sup>
145
146Defines the Bluetooth scanning information.
147
148**System capability**: SystemCapability.Location.Location.Core
149
150**System API**: This is a system API.
151
152| Name| Type| Read Only| Optional| Description|
153| -------- | -------- | -------- | -------- | -------- |
154| deviceName | string | No| No| Name of a Bluetooth device.|
155| macAddress | string | No| No| MAC address of a Bluetooth device.|
156| rssi | number | No| No| Signal strength of a Bluetooth device, in dBm.|
157| timestamp | number | No| No| Scanning timestamp.|
158
159## LocationPrivacyType
160
161Defines the privacy statement type.
162
163**System capability**: SystemCapability.Location.Location.Core
164
165**System API**: This is a system API.
166
167| Name| Value| Description|
168| -------- | -------- | -------- |
169| OTHERS | 0 | Other scenarios. Reserved field.|
170| STARTUP | 1 | Privacy statement displayed in the startup wizard. The user needs to choose whether to agree with the statement.|
171| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.|
172
173## LocatingRequiredDataType<sup>10+</sup>
174
175Defines the type of the required data of the location service.
176
177**System capability**: SystemCapability.Location.Location.Core
178
179**System API**: This is a system API.
180
181| Name| Value| Description|
182| -------- | -------- | -------- |
183| WIFI  | 1 | Wi-Fi scanning information.|
184| BLUETOOTH | 2 | Bluetooth scanning information.|
185
186
187## LocationIconStatus<sup>12+</sup>
188
189Defines the location icon status.
190
191**System capability**: SystemCapability.Location.Location.Core
192
193**System API**: This is a system API.
194
195| Name| Value| Description|
196| -------- | -------- | -------- |
197| LOCATING_NOT_STARTED  | 0 | No location services are available and the location icon does not need to be displayed.|
198| LOCATING_STARTED | 1 | Common location is in progress, and the common location icon needs to be displayed.|
199| HD_LOCATING_STARTED | 2 | High-precision location is in progress, and the high-precision location icon needs to be displayed.|
200
201
202## geoLocationManager.on('locatingRequiredDataChange')<sup>10+</sup>
203
204on(type: 'locatingRequiredDataChange', config: LocatingRequiredDataConfig, callback: Callback&lt;Array&lt;LocatingRequiredData&gt;&gt;): void
205
206Subscribes to changes in the required data of the location service, including Wi-Fi and Bluetooth scanning information. An application can then determine whether to enable Wi-Fi and Bluetooth scanning based on the return result. This API uses an asynchronous callback to return the result.
207
208**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
209
210**System capability**: SystemCapability.Location.Location.Core
211
212**System API**: This is a system API.
213
214**Parameters**
215
216  | Name| Type| Mandatory| Description|
217  | -------- | -------- | -------- | -------- |
218  | type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.|
219  | config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.|
220  | callback | Callback&lt;Array&lt;[LocatingRequiredData](#locatingrequireddata10)&gt;&gt; | Yes| Callback used to return the data required by the location service.|
221
222**Error codes**
223
224For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
225
226| ID| Error Message|
227| -------- | ---------------------------------------- |
228|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
229|202 | Permission verification failed. A non-system application calls a system API. |
230|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
231|801 | Capability not supported. Failed to call ${geoLocationManager.on('locatingRequiredDataChange')} due to limited device capabilities.          |
232|3301800 | Failed to start WiFi or Bluetooth scanning.                            |
233
234**Example**
235
236  ```ts
237  import { geoLocationManager } from '@kit.LocationKit';
238  let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => {
239      console.info('locatingRequiredDataChange: ' + JSON.stringify(code));
240  }
241  let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
242  try {
243      geoLocationManager.on('locatingRequiredDataChange', config, callback);
244  } catch (err) {
245      console.error("errCode:" + err.code + ", message:"  + err.message);
246  }
247  ```
248
249
250## geoLocationManager.off('locatingRequiredDataChange')<sup>10+</sup>
251
252off(type: 'locatingRequiredDataChange', callback?: Callback&lt;Array&lt;LocatingRequiredData&gt;&gt;): void
253
254Unsubscribes from changes in the required data of the location service and stops Wi-Fi and Bluetooth scanning.
255
256**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
257
258**System capability**: SystemCapability.Location.Location.Core
259
260**System API**: This is a system API.
261
262**Parameters**
263
264  | Name| Type| Mandatory| Description|
265  | -------- | -------- | -------- | -------- |
266  | type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.|
267  | callback | Callback&lt;Array&lt;[LocatingRequiredData](#locatingrequireddata10)&gt;&gt; | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
268
269**Error codes**
270
271For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
272
273| ID| Error Message|
274| -------- | ---------------------------------------- |
275|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
276|202 | Permission verification failed. A non-system application calls a system API. |
277|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
278|801 | Capability not supported. Failed to call ${geoLocationManager.off('locatingRequiredDataChange')} due to limited device capabilities.          |
279
280**Example**
281
282  ```ts
283  import { geoLocationManager } from '@kit.LocationKit';
284  let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => {
285      console.info('locatingRequiredDataChange: ' + JSON.stringify(code));
286  }
287  let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
288  try {
289      geoLocationManager.on('locatingRequiredDataChange', config, callback);
290      geoLocationManager.off('locatingRequiredDataChange', callback);
291  } catch (err) {
292      console.error("errCode:" + err.code + ", message:"  + err.message);
293  }
294  ```
295
296## geoLocationManager.enableLocation
297
298enableLocation(callback: AsyncCallback&lt;void&gt;): void
299
300Enables the location service. This API uses an asynchronous callback to return the result.
301
302**System API**: This is a system API.
303
304**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
305
306**System capability**: SystemCapability.Location.Location.Core
307
308**Parameters**
309
310  | Name| Type| Mandatory| Description|
311  | -------- | -------- | -------- | -------- |
312  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the location service is successfully enabled, **err** is **undefined**. Otherwise, **err** is an error object.|
313
314**Error codes**
315
316For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
317
318| ID| Error Message|
319| -------- | ---------------------------------------- |
320|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
321|202 | Permission verification failed. A non-system application calls a system API. |
322|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
323|801 | Capability not supported. Failed to call ${geoLocationManager.enableLocation} due to limited device capabilities.          |
324|3301000 | The location service is unavailable.                                              |
325
326**Example**
327
328  ```ts
329  import { geoLocationManager } from '@kit.LocationKit';
330  try {
331      geoLocationManager.enableLocation((err) => {
332          if (err) {
333              console.error('enableLocation: err=' + JSON.stringify(err));
334          }
335      });
336  } catch (err) {
337      console.error("errCode:" + err.code + ", message:"  + err.message);
338  }
339  ```
340
341
342## geoLocationManager.enableLocation
343
344enableLocation(): Promise&lt;void&gt;
345
346Enables the location service. This API uses a promise to return the result.
347
348**System API**: This is a system API.
349
350**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
351
352**System capability**: SystemCapability.Location.Location.Core
353
354**Return value**
355
356  | Type| Description|
357  | -------- | -------- |
358  | Promise&lt;void&gt; | Promise that returns no value.|
359
360**Error codes**
361
362For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
363
364| ID| Error Message|
365| -------- | ---------------------------------------- |
366|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
367|202 | Permission verification failed. A non-system application calls a system API. |
368|801 | Capability not supported. Failed to call ${geoLocationManager.enableLocation} due to limited device capabilities.          |
369|3301000 | The location service is unavailable.                                            |
370
371**Example**
372
373  ```ts
374  import { geoLocationManager } from '@kit.LocationKit';
375  import { BusinessError } from '@kit.BasicServicesKit';
376  try {
377      geoLocationManager.enableLocation().then(() => {
378          console.info('promise, enableLocation succeed');
379      })
380      .catch((error:BusinessError) => {
381          console.error('promise, enableLocation: error=' + JSON.stringify(error));
382      });
383  } catch (err) {
384      console.error("errCode:" + err.code + ", message:"  + err.message);
385  }
386  ```
387
388## geoLocationManager.disableLocation
389
390disableLocation(): void
391
392Disables the location service.
393
394**System API**: This is a system API.
395
396**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
397
398**System capability**: SystemCapability.Location.Location.Core
399
400**Error codes**
401
402For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
403
404| ID| Error Message|
405| -------- | ---------------------------------------- |
406|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
407|202 | Permission verification failed. A non-system application calls a system API. |
408|801 | Capability not supported. Failed to call ${geoLocationManager.disableLocation} due to limited device capabilities.          |
409|3301000 | The location service is unavailable.                                            |
410
411**Example**
412
413  ```ts
414  import { geoLocationManager } from '@kit.LocationKit';
415  try {
416      geoLocationManager.disableLocation();
417  } catch (err) {
418      console.error("errCode:" + err.code + ", message:"  + err.message);
419  }
420  ```
421
422## geoLocationManager.enableLocationMock
423
424enableLocationMock(): void
425
426Enables the mock location function.
427
428**System capability**: SystemCapability.Location.Location.Core
429
430**System API**: This is a system API.
431
432**Error codes**
433
434For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
435
436| ID| Error Message|
437| -------- | ---------------------------------------- |
438|202 | Permission verification failed. A non-system application calls a system API. |
439|801 | Capability not supported. Failed to call ${geoLocationManager.enableLocationMock} due to limited device capabilities.          |
440|3301000 | The location service is unavailable.                                            |
441|3301100 | The location switch is off.|
442
443**Example**
444
445  ```ts
446  import { geoLocationManager } from '@kit.LocationKit';
447  try {
448      geoLocationManager.enableLocationMock();
449  } catch (err) {
450      console.error("errCode:" + err.code + ", message:"  + err.message);
451  }
452  ```
453
454
455## geoLocationManager.disableLocationMock
456
457disableLocationMock(): void
458
459Disables the mock location function.
460
461**System capability**: SystemCapability.Location.Location.Core
462
463**System API**: This is a system API.
464
465**Error codes**
466
467For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
468
469| ID| Error Message|
470| -------- | ---------------------------------------- |
471|202 | Permission verification failed. A non-system application calls a system API. |
472|801 | Capability not supported. Failed to call ${geoLocationManager.disableLocationMock} due to limited device capabilities.          |
473|3301000 | The location service is unavailable.                                            |
474|3301100 | The location switch is off.|
475
476**Example**
477
478  ```ts
479  import { geoLocationManager } from '@kit.LocationKit';
480  try {
481      geoLocationManager.disableLocationMock();
482  } catch (err) {
483      console.error("errCode:" + err.code + ", message:"  + err.message);
484  }
485  ```
486
487
488## geoLocationManager.setMockedLocations
489
490setMockedLocations(config: LocationMockConfig): void
491
492Sets the mock location information. The mock locations will be reported at the interval specified in this API.
493
494This API can be invoked only after [geoLocationManager.enableLocationMock](#geolocationmanagerenablelocationmock) is called.
495
496**System capability**: SystemCapability.Location.Location.Core
497
498**System API**: This is a system API.
499
500**Parameters**
501
502  | Name| Type| Mandatory| Description|
503  | -------- | -------- | -------- | -------- |
504  | config |  [LocationMockConfig](#locationmockconfig) | Yes| Mock location information, including the interval for reporting the mock locations and the array of the mock locations.|
505
506**Error codes**
507
508For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
509
510| ID| Error Message|
511| -------- | ---------------------------------------- |
512|202 | Permission verification failed. A non-system application calls a system API. |
513|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
514|801 | Capability not supported. Failed to call ${geoLocationManager.setMockedLocations} due to limited device capabilities.          |
515|3301000 | The location service is unavailable.                                            |
516|3301100 | The location switch is off.|
517
518**Example**
519
520  ```ts
521  import { geoLocationManager } from '@kit.LocationKit';
522  let locations:Array<geoLocationManager.Location> = [
523      {"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true},
524      {"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true},
525      {"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true},
526      {"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true},
527      {"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true}
528  ];
529  let config:geoLocationManager.LocationMockConfig = {"timeInterval": 5, "locations": locations};
530  try {
531      geoLocationManager.enableLocationMock();
532      geoLocationManager.setMockedLocations(config);
533  } catch (err) {
534      console.error("errCode:" + err.code + ", message:"  + err.message);
535  }
536  ```
537
538
539## geoLocationManager.enableReverseGeocodingMock
540
541enableReverseGeocodingMock(): void
542
543Enables the mock reverse geocoding function.
544
545**System capability**: SystemCapability.Location.Location.Core
546
547**System API**: This is a system API.
548
549**Error codes**
550
551For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
552
553| ID| Error Message|
554| -------- | ---------------------------------------- |
555|202 | Permission verification failed. A non-system application calls a system API. |
556|801 | Capability not supported. Failed to call ${geoLocationManager.enableReverseGeocodingMock} due to limited device capabilities.          |
557|3301000 | The location service is unavailable.                                            |
558
559**Example**
560
561  ```ts
562  import { geoLocationManager } from '@kit.LocationKit';
563  try {
564      geoLocationManager.enableReverseGeocodingMock();
565  } catch (err) {
566      console.error("errCode:" + err.code + ", message:"  + err.message);
567  }
568  ```
569
570
571## geoLocationManager.disableReverseGeocodingMock
572
573disableReverseGeocodingMock(): void
574
575Disables the mock geocoding function.
576
577**System capability**: SystemCapability.Location.Location.Core
578
579**System API**: This is a system API.
580
581**Error codes**
582
583For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
584
585| ID| Error Message|
586| -------- | ---------------------------------------- |
587|202 | Permission verification failed. A non-system application calls a system API. |
588|801 | Capability not supported. Failed to call ${geoLocationManager.disableReverseGeocodingMock} due to limited device capabilities.          |
589|3301000 | The location service is unavailable.                                            |
590
591**Example**
592
593  ```ts
594  import { geoLocationManager } from '@kit.LocationKit';
595  try {
596      geoLocationManager.disableReverseGeocodingMock();
597  } catch (err) {
598      console.error("errCode:" + err.code + ", message:"  + err.message);
599  }
600  ```
601
602
603## geoLocationManager.setReverseGeocodingMockInfo
604
605setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;): void
606
607Sets information of the mock reverse geocoding function, including the mapping between a location and geographical name. If the location is contained in the configurations during reverse geocoding query, the corresponding geographical name will be returned.
608
609This API can be invoked only after [geoLocationManager.enableReverseGeocodingMock](#geolocationmanagerenablereversegeocodingmock) is called.
610
611**System capability**: SystemCapability.Location.Location.Core
612
613**System API**: This is a system API.
614
615**Parameters**
616
617  | Name| Type| Mandatory| Description|
618  | -------- | -------- | -------- | -------- |
619  | mockInfos | Array&lt;[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)&gt; | Yes| Array of information of the mock reverse geocoding function, including a location and a geographical name.|
620
621**Error codes**
622
623For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
624
625| ID| Error Message|
626| -------- | ---------------------------------------- |
627|202 | Permission verification failed. A non-system application calls a system API. |
628|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
629|801 | Capability not supported. Failed to call ${geoLocationManager.setReverseGeocodingMockInfo} due to limited device capabilities.          |
630|3301000 | The location service is unavailable.                                            |
631
632**Example**
633
634  ```ts
635  import { geoLocationManager } from '@kit.LocationKit';
636  let mockInfos:Array<geoLocationManager.ReverseGeocodingMockInfo> = [
637      {"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "isFromMock": true}},
638      {"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "isFromMock": true}},
639      {"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "isFromMock": true}},
640      {"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "isFromMock": true}},
641      {"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "isFromMock": true}},
642  ];
643  try {
644      geoLocationManager.enableReverseGeocodingMock();
645      geoLocationManager.setReverseGeocodingMockInfo(mockInfos);
646  } catch (err) {
647      console.error("errCode:" + err.code + ", message:"  + err.message);
648  }
649  ```
650
651
652## geoLocationManager.isLocationPrivacyConfirmed
653
654isLocationPrivacyConfirmed(type: LocationPrivacyType): boolean
655
656Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications.
657
658**System API**: This is a system API.
659
660**System capability**: SystemCapability.Location.Location.Core
661
662**Parameters**
663
664  | Name| Type| Mandatory| Description|
665  | -------- | -------- | -------- | -------- |
666  | 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.|
667
668**Return value**
669
670  | Type| Description|
671  | -------- | -------- |
672  | boolean | **true**: The user agrees to the privacy statement of the location service.<br>**false**: The user does not agree to the privacy statement of the location service.|
673
674**Error codes**
675
676For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
677
678| ID| Error Message|
679| -------- | ---------------------------------------- |
680|202 | Permission verification failed. A non-system application calls a system API. |
681|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
682|801 | Capability not supported. Failed to call ${geoLocationManager.isLocationPrivacyConfirmed} due to limited device capabilities.          |
683|3301000 | The location service is unavailable.                                            |
684
685**Example**
686
687  ```ts
688  import { geoLocationManager } from '@kit.LocationKit';
689  try {
690      let isConfirmed = geoLocationManager.isLocationPrivacyConfirmed(1);
691  } catch (err) {
692      console.error("errCode:" + err.code + ", message:"  + err.message);
693  }
694  ```
695
696
697## geoLocationManager.setLocationPrivacyConfirmStatus
698
699setLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean): void
700
701Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications.
702
703**System API**: This is a system API.
704
705**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
706
707**System capability**: SystemCapability.Location.Location.Core
708
709**Parameters**
710
711  | Name| Type| Mandatory| Description|
712  | -------- | -------- | -------- | -------- |
713  | 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.|
714  | isConfirmed | boolean | Yes| **true**: The user agrees to the privacy statement of the location service.<br>**false**: The user does not agree to the privacy statement of the location service.|
715
716**Error codes**
717
718For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
719
720| ID| Error Message|
721| -------- | ---------------------------------------- |
722|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
723|202 | Permission verification failed. A non-system application calls a system API. |
724|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
725|801 | Capability not supported. Failed to call ${geoLocationManager.setLocationPrivacyConfirmStatus} due to limited device capabilities.          |
726|3301000 | The location service is unavailable.                                            |
727
728**Example**
729
730  ```ts
731  import { geoLocationManager } from '@kit.LocationKit';
732  try {
733      geoLocationManager.setLocationPrivacyConfirmStatus(1, true);
734  } catch (err) {
735      console.error("errCode:" + err.code + ", message:"  + err.message);
736  }
737  ```
738
739
740## geoLocationManager.getLocatingRequiredData<sup>10+</sup>
741
742getLocatingRequiredData(config: LocatingRequiredDataConfig): Promise&lt;Array&lt;LocatingRequiredData&gt;&gt;
743
744Obtains the required data of the location service. This API uses a promise to return the result.
745
746**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
747
748**System capability**: SystemCapability.Location.Location.Core
749
750**System API**: This is a system API.
751
752**Parameters**
753
754  | Name| Type| Mandatory| Description|
755  | -------- | -------- | -------- | -------- |
756  | config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.|
757
758**Return value**
759
760  | Type| Description|
761  | -------- | -------- |
762  | Promise&lt;Array&lt;[LocatingRequiredData](#locatingrequireddata10)&gt;&gt; | Promise used to return the required data for the location service, such as the Wi-Fi and Bluetooth scanning information.|
763
764**Error codes**
765
766For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
767
768| ID| Error Message|
769| -------- | ---------------------------------------- |
770|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
771|202 | Permission verification failed. A non-system application calls a system API. |
772|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
773|801 | Capability not supported. Failed to call ${geoLocationManager.getLocatingRequiredData} due to limited device capabilities.          |
774|3301800  | Failed to start WiFi or Bluetooth scanning.                    |
775
776**Example**
777
778  ```ts
779  import { geoLocationManager } from '@kit.LocationKit';
780  import { BusinessError } from '@kit.BasicServicesKit';
781  let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
782  try {
783      geoLocationManager.getLocatingRequiredData(config).then((result) => {
784          console.info('getLocatingRequiredData return: ' + JSON.stringify(result));
785      })
786      .catch((error:BusinessError) => {
787          console.error('promise, getLocatingRequiredData: error=' + JSON.stringify(error));
788      });
789  } catch (err) {
790      console.error("errCode:" + err.code + ", message:"  + err.message);
791  }
792  ```
793
794
795## geoLocationManager.on('locationIconStatusChange')<sup>12+</sup>
796
797on(type: 'locationIconStatusChange', callback: Callback&lt;LocationIconStatus&gt;): void
798
799Subscribes to status changes of the location icon. This API uses an asynchronous callback to return the result.
800
801**System capability**: SystemCapability.Location.Location.Core
802
803**System API**: This is a system API.
804
805**Parameters**
806
807  | Name| Type| Mandatory| Description|
808  | -------- | -------- | -------- | -------- |
809  | type | string | Yes| Event type. Event type. The value **locationIconStatusChange** indicates status changes of the location icon.|
810  | callback | Callback&lt;[LocationIconStatus](#locationiconstatus12)&gt; | Yes| Callback used to return the location icon status.|
811
812**Error codes**
813
814For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
815
816| ID| Error Message|
817| -------- | ---------------------------------------- |
818|202 | Permission verification failed. A non-system application calls a system API. |
819|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
820|801 | Capability not supported. Failed to call ${geoLocationManager.on('locationIconStatusChange')} due to limited device capabilities.          |
821|3301000 | The location service is unavailable.                        |
822
823**Example**
824
825  ```ts
826  import { geoLocationManager } from '@kit.LocationKit';
827  let callback = (code: geoLocationManager.LocationIconStatus):void => {
828      console.info('LocationIconStatus: ' + JSON.stringify(code));
829  }
830  try {
831      geoLocationManager.on('locationIconStatusChange', callback);
832  } catch (err) {
833      console.error("errCode:" + err.code + ", message:"  + err.message);
834  }
835  ```
836
837
838## geoLocationManager.off('locationIconStatusChange')<sup>12+</sup>
839
840off(type: 'locationIconStatusChange', callback?: Callback&lt;LocationIconStatus&gt;): void
841
842Unsubscribes from status changes of the location icon.
843
844**System capability**: SystemCapability.Location.Location.Core
845
846**System API**: This is a system API.
847
848**Parameters**
849
850  | Name| Type| Mandatory| Description|
851  | -------- | -------- | -------- | -------- |
852  | type | string | Yes| Event type. Event type. The value **locationIconStatusChange** indicates status changes of the location icon.|
853  | callback | Callback&lt;[LocationIconStatus](#locationiconstatus12)&gt;  | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
854
855**Error codes**
856
857For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
858
859| ID| Error Message|
860| -------- | ---------------------------------------- |
861|202 | Permission verification failed. A non-system application calls a system API. |
862|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
863|801 | Capability not supported. Failed to call ${geoLocationManager.off('locationIconStatusChange')} due to limited device capabilities.          |
864|3301000 | The location service is unavailable.        |
865
866**Example**
867
868  ```ts
869  import { geoLocationManager } from '@kit.LocationKit';
870  let callback = (code: geoLocationManager.LocationIconStatus):void => {
871      console.info('LocationIconStatus: ' + JSON.stringify(code));
872  }
873  try {
874      geoLocationManager.on('locationIconStatusChange', callback);
875	  geoLocationManager.off('locationIconStatusChange', callback);
876  } catch (err) {
877      console.error("errCode:" + err.code + ", message:"  + err.message);
878  }
879  ```
880
881
882## geoLocationManager.getLocationIconStatus<sup>12+</sup>
883
884getLocationIconStatus(): LocationIconStatus
885
886Obtains the current location icon status.
887
888**System capability**: SystemCapability.Location.Location.Core
889
890**System API**: This is a system API.
891
892**Return value**
893
894  | Type| Description|
895  | -------- | -------- |
896  | [LocationIconStatus](#locationiconstatus12) | Location icon status.|
897
898**Error codes**
899
900For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md).
901
902| ID| Error Message|
903| -------- | ---------------------------------------- |
904|202 | Permission verification failed. A non-system application calls a system API. |
905|801 | Capability not supported. Failed to call ${geoLocationManager.getLocationIconStatus} due to limited device capabilities.          |
906|3301000  | The location service is unavailable.                  |
907
908**Example**
909
910  ```ts
911  import { geoLocationManager } from '@kit.LocationKit';
912  try {
913      let iconStatus = geoLocationManager.getLocationIconStatus();
914  } catch (err) {
915      console.error("errCode:" + err.code + ", message:"  + err.message);
916  }
917  ```
918