• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.geoLocationManager (Geolocation Manager)
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
9## Applying for Permissions
10
11Before 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.
12
13The system provides the following location permissions:
14- ohos.permission.LOCATION
15
16- ohos.permission.APPROXIMATELY_LOCATION
17
18- ohos.permission.LOCATION_IN_BACKGROUND
19
20If your application needs to access the device location information, it must first apply for required permissions. Specifically speaking:
21
22API versions earlier than 9: Apply for **ohos.permission.LOCATION**.
23
24API 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.
25
26| API Version| Location Permission| Permission Application Result| Location Accuracy|
27| -------- | -------- | -------- | -------- |
28| Earlier than 9| ohos.permission.LOCATION | Success| Location accurate to meters|
29| 9 and later| ohos.permission.LOCATION | Failure| No location obtained|
30| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers|
31| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters|
32
33To access the device location information when running in the background, an application needs to request for the **ohos.permission.LOCATION_IN_BACKGROUND** permission or a continuous task of the background mode. In this way, the system continues to report device location information after your application moves to the background.
34
35A 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).
36
37For details about how to request for a continuous task, see [Continuous Task](../../task-management/continuous-task.md).
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 '@ohos.geoLocationManager';
46```
47
48
49## ReverseGeoCodeRequest
50
51Defines a reverse geocoding request.
52
53**System capability**: SystemCapability.Location.Location.Geocoder
54
55| Name| Type| Readable| Writable| Description|
56| -------- | -------- | -------- | -------- | -------- |
57| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
58| latitude | number | Yes| Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.|
59| longitude | number | Yes| Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.|
60| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The specified value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
61
62
63## GeoCodeRequest
64
65Defines a geocoding request.
66
67**System capability**: SystemCapability.Location.Location.Geocoder
68
69| Name| Type| Readable|Writable| Description|
70| -------- | -------- | -------- | -------- | -------- |
71| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
72| description | string | Yes| Yes| Location description, for example, **No. xx, xx Road, Pudong New District, Shanghai**.|
73| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The specified value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
74| minLatitude | number | Yes| Yes| Minimum latitude. This parameter is used with **minLongitude**, **maxLatitude**, and **maxLongitude** to specify the latitude and longitude ranges. The value ranges from **-90** to **90**.|
75| minLongitude | number | Yes| Yes| Minimum longitude. The value ranges from **-180** to **180**.|
76| maxLatitude | number | Yes| Yes| Maximum latitude. The value ranges from **-90** to **90**.|
77| maxLongitude | number | Yes| Yes| Maximum longitude. The value ranges from **-180** to **180**.|
78
79
80## GeoAddress
81
82Defines a geographic location.
83
84**System capability**: SystemCapability.Location.Location.Geocoder
85
86| Name| Type| Readable|Writable| Description|
87| -------- | -------- | -------- | -------- | -------- |
88| latitude | number | Yes| No | Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.|
89| longitude | number | Yes| No | Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.|
90| locale | string | Yes| No | Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
91| placeName | string | Yes| No | Landmark of the location.|
92| countryCode | string | Yes| No | Country code.|
93| countryName | string| Yes| No| Country name.|
94| administrativeArea | string | Yes| No| Level-1 administrative region, which is generally is a province or state.|
95| subAdministrativeArea | string | Yes| No| Level-2 administrative region, which is generally is a city.|
96| locality | string | Yes| No| Locality information, which is usually a city.|
97| subLocality | string | Yes| No| Sub-locality information, which is usually a district or county.|
98| roadName | string | Yes| No| Road name.|
99| subRoadName | string | Yes| No| Auxiliary road information.|
100| premises | string| Yes| No| House information.|
101| postalCode | string | Yes| No| Postal code.|
102| phoneNumber | string | Yes| No| Phone number.|
103| addressUrl | string | Yes| No| Website URL.|
104| descriptions | Array<string> | Yes| No| Additional description. It contains **cityCode** (the array subscript is **0**) and **adminCode** (the array subscript is **1**), for example, **["025","320114001"]**.|
105| descriptionsSize | number | Yes| No| Total number of additional descriptions. The specified value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
106| isFromMock | Boolean | Yes| No| Whether the geographical name is from the mock reverse geocoding function.<br>**System API**: This is a system API.|
107
108
109## LocationRequest
110
111Defines a location request.
112
113**System capability**: SystemCapability.Location.Location.Core
114
115| Name| Type| Readable|Writable| Description|
116| -------- | -------- | -------- | -------- | -------- |
117| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request. This parameter is effective only when **scenario** is set to **UNSET**. If this parameter and **scenario** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestPriority](#locationrequestpriority).|
118| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request. The **priority** parameter is effective only when this parameter is set to **UNSET**. If this parameter and **priority** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestScenario](#locationrequestscenario).|
119| timeInterval | number | Yes| Yes| Time interval at which location information is reported, in seconds. The specified value must be greater than or equal to **0**. The default value is **1**.|
120| distanceInterval | number | Yes| Yes| Distance interval at which location information is reported, in meters. The specified value must be greater than or equal to **0**. The default value is **0**.|
121| maxAccuracy | number | Yes| Yes| Location accuracy, in meters. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled. The specified value must be greater than or equal to **0**. The default value is **0**.|
122
123
124## CurrentLocationRequest
125
126Defines the current location request.
127
128**System capability**: SystemCapability.Location.Location.Core
129
130| Name| Type| Readable|Writable| Description|
131| -------- | -------- | -------- | -------- | -------- |
132| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request. This parameter is effective only when **scenario** is set to **UNSET**. If this parameter and **scenario** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestPriority](#locationrequestpriority).|
133| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request. The **priority** parameter is effective only when this parameter is set to **UNSET**. If this parameter and **priority** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestScenario](#locationrequestscenario).|
134| maxAccuracy | number | Yes| Yes| Location accuracy, in meters. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled. The specified value must be greater than or equal to **0**. The default value is **0**.|
135| timeoutMs | number | Yes| Yes| Timeout duration, in milliseconds. The minimum value is **1000**. The specified value must be greater than or equal to **1000**.|
136
137
138## SatelliteStatusInfo
139
140Defines the satellite status information.
141
142**System capability**: SystemCapability.Location.Location.Gnss
143
144| Name| Type| Readable|Writable| Description|
145| -------- | -------- | -------- | -------- | -------- |
146| satellitesNumber | number | Yes| No| Number of satellites. The specified value must be greater than or equal to **0**.|
147| satelliteIds | Array&lt;number&gt; | Yes| No| Array of satellite IDs. The specified value must be greater than or equal to **0**.|
148| carrierToNoiseDensitys | Array&lt;number&gt; | Yes| No| Carrier-to-noise density ratio, that is, **cn0**. The specified value must be greater than **0**.|
149| altitudes | Array&lt;number&gt; | Yes| No| Satellite altitude angle information. The value ranges from **-90** to **90**, in degrees.|
150| azimuths | Array&lt;number&gt; | Yes| No| Azimuth information. The value ranges from **0** to **360**, in degrees.|
151| carrierFrequencies | Array&lt;number&gt; | Yes| No| Carrier frequency, in Hz. The specified value must be greater than or equal to **0**.|
152
153
154## CachedGnssLocationsRequest
155
156Defines a request for reporting cached GNSS locations.
157
158**System capability**: SystemCapability.Location.Location.Gnss
159
160| Name| Type| Readable|Writable| Description|
161| -------- | -------- | -------- | -------- | -------- |
162| reportingPeriodSec | number | Yes| Yes| Interval for reporting the cached GNSS locations, in milliseconds. The specified value must be greater than **0**.|
163| 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.|
164
165
166## Geofence
167
168Defines a GNSS geofence. Currently, only circular geofences are supported.
169
170**System capability**: SystemCapability.Location.Location.Geofence
171
172| Name| Type| Readable|Writable| Description|
173| -------- | -------- | -------- | -------- | -------- |
174| latitude | number | Yes| Yes|Latitude information. The value ranges from **-90** to **90**.|
175| longitude | number | Yes|Yes| Longitude information. The value ranges from **-180** to **180**.|
176| radius | number | Yes|Yes| Radius of a circular geofence, in meters. The specified value must be greater than **0**.|
177| expiration | number | Yes|Yes| Expiration period of a geofence, in milliseconds. The specified value must be greater than **0**.|
178
179
180## GeofenceRequest
181
182Defines a GNSS geofencing request.
183
184**System capability**: SystemCapability.Location.Location.Geofence
185
186| Name| Type| Readable|Writable| Description|
187| -------- | -------- | -------- | -------- | -------- |
188| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes |  Location scenario.|
189| geofence |  [Geofence](#geofence)| Yes| Yes |  Geofence information.|
190
191
192## LocationCommand
193
194Defines an extended command.
195
196**System capability**: SystemCapability.Location.Location.Core
197
198| Name| Type| Readable|Writable| Description|
199| -------- | -------- | -------- | -------- | -------- |
200| scenario | [LocationRequestScenario](#locationrequestscenario)  | Yes| Yes | Location scenario.|
201| command | string | Yes| Yes | Extended command, in the string format.|
202
203
204## Location
205
206Defines a location.
207
208**System capability**: SystemCapability.Location.Location.Core
209
210| Name| Type| Readable|Writable| Description|
211| -------- | -------- | -------- | -------- | -------- |
212| latitude | number| Yes| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.|
213| longitude | number| Yes| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.|
214| altitude | number | Yes| No| Location altitude, in meters.|
215| accuracy | number | Yes| No| Location accuracy, in meters.|
216| speed | number | Yes| No|Speed, in m/s.|
217| timeStamp | number | Yes| No| Location timestamp in the UTC format.|
218| direction | number | Yes| No| Direction information. The value ranges from **0** to **360**, in degrees.|
219| timeSinceBoot | number | Yes| No| Location timestamp since boot.|
220| additions | Array&lt;string&gt; | Yes| No| Additional description.|
221| additionSize | number | Yes| No| Number of additional descriptions. The specified value must be greater than or equal to **0**. |
222| isFromMock | Boolean | Yes| No| Whether the location information is from the mock location function.<br>**System API**: This is a system API.|
223
224
225## ReverseGeocodingMockInfo
226
227Defines the configuration of the mock reverse geocoding function.
228
229**System capability**: SystemCapability.Location.Location.Core
230
231**System API**: This is a system API.
232
233| Name| Type| Readable|Writable| Description|
234| -------- | -------- | -------- | -------- | -------- |
235| location |  [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Yes| Latitude and longitude information.|
236| geoAddress |  [GeoAddress](#geoaddress) | Yes| Yes|Geographical name.|
237
238
239## LocationMockConfig
240
241Defines the configuration of the mock location function.
242
243**System capability**: SystemCapability.Location.Location.Core
244
245**System API**: This is a system API.
246
247| Name| Type| Readable|Writable| Description|
248| -------- | -------- | -------- | -------- | -------- |
249| timeInterval | number | Yes| Yes| Time interval at which mock locations are reported, in seconds.|
250| locations | Array&lt;[Location](#location)&gt; | Yes| Yes| Array of mocked locations.|
251
252
253## CountryCode
254
255Defines the country code information.
256
257**System capability**: SystemCapability.Location.Location.Core
258
259| Name| Type| Readable|Writable| Description|
260| -------- | -------- | -------- | -------- | -------- |
261| country | string | Yes| No| Country code.|
262| type |  [CountryCodeType](#countrycodetype) | Yes| No| Country code source.|
263
264
265## LocatingRequiredDataConfig<sup>10+</sup>
266
267Defines the configuration for obtaining the required data of the location service.
268
269**System capability**: SystemCapability.Location.Location.Core
270
271**System API**: This is a system API.
272
273| Name| Type| Readable|Writable| Description|
274| -------- | -------- | -------- | -------- | -------- |
275| type | [LocatingRequiredDataType](#locatingrequireddatatype10) | Yes| Yes| Type of the required data.|
276| needStartScan |  boolean | Yes| Yes| Whether to initiate scanning.|
277| scanInterval |  number | Yes| Yes| Scanning interval, in milliseconds. The specified value must be greater than **0**. The default value is **10000**.|
278| scanTimeout |  number | Yes| Yes| Scanning timeout interval, in milliseconds. The value ranges from **0** to **600000**. The default value is **10000**.|
279
280
281## LocatingRequiredData<sup>10+</sup>
282
283Defines 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.
284
285**System capability**: SystemCapability.Location.Location.Core
286
287**System API**: This is a system API.
288
289| Name| Type| Readable|Writable| Description|
290| -------- | -------- | -------- | -------- | -------- |
291| wifiData | [WifiScanInfo](#wifiscaninfo10) | Yes| No| Wi-Fi scanning result.|
292| bluetoothData |  [BluetoothScanInfo](#bluetoothscaninfo10) | Yes| No| Bluetooth scanning result.|
293
294
295## WifiScanInfo<sup>10+</sup>
296
297Defines the Wi-Fi scanning information, including the SSID, BSSID, and RSSI of the scanned Wi-Fi hotspot.
298
299**System capability**: SystemCapability.Location.Location.Core
300
301**System API**: This is a system API.
302
303| Name| Type| Readable|Writable| Description|
304| -------- | -------- | -------- | -------- | -------- |
305| ssid | string | Yes| No| Service set identifier (SSID) of a Wi-Fi hotspot, in UTF-8 format.|
306| bssid | string | Yes| No| Base station subsystem identifier (BSSID) of a Wi-Fi hotspot.|
307| rssi | number | Yes| No| Received signal strength indicator (RSSI) of a Wi-Fi hotspot, in dBm.|
308| frequency | number | Yes| No| Frequency of a Wi-Fi hotspot.|
309| timestamp | number | Yes| No| Scanning timestamp.|
310
311
312## BluetoothScanInfo<sup>10+</sup>
313
314Defines the Bluetooth scanning information.
315
316**System capability**: SystemCapability.Location.Location.Core
317
318**System API**: This is a system API.
319
320| Name| Type| Readable|Writable| Description|
321| -------- | -------- | -------- | -------- | -------- |
322| deviceName | string | Yes| No| Name of a Bluetooth device.|
323| macAddress | string | Yes| No| MAC address of a Bluetooth device.|
324| rssi | number | Yes| No| Signal strength of a Bluetooth device, in dBm.|
325| timestamp | number | Yes| No| Scanning timestamp.|
326
327
328## LocationRequestPriority
329
330Sets the priority of the location request.
331
332**System capability**: SystemCapability.Location.Location.Core
333
334| Name| Value| Description|
335| -------- | -------- | -------- |
336| UNSET | 0x200 | Priority unspecified.<br>If this option is used, [LocationRequestPriority](#locationrequestpriority) is invalid.|
337| ACCURACY | 0x201 | Location accuracy.<br>This policy mainly uses the GNSS positioning technology. In an open area, the technology can achieve the meter-level location accuracy, depending on the hardware performance of the device. However, in a shielded environment, the location accuracy may significantly decrease.|
338| LOW_POWER | 0x202 | Power efficiency.<br>This policy mainly uses the base station positioning, WLAN positioning, and Bluetooth positioning technologies to obtain device location in both indoor and outdoor scenarios. The location accuracy depends on the distribution of surrounding base stations, visible WLANs, and Bluetooth devices and therefore may fluctuate greatly. This policy is recommended and can reduce power consumption when your application does not require high location accuracy or when base stations, visible WLANs, and Bluetooth devices are densely distributed.|
339| FIRST_FIX | 0x203 | Fast location preferred. Use this option if you want to obtain a location as fast as possible.<br>This policy uses the GNSS positioning, base station positioning, WLAN positioning, and Bluetooth positioning technologies simultaneously to obtain the device location in both the indoor and outdoor scenarios. When all positioning technologies provide a location result, the system provides the most accurate location result for your application. It can lead to significant hardware resource consumption and power consumption.|
340
341
342## LocationRequestScenario
343
344  Sets the scenario of the location request.
345
346**System capability**: SystemCapability.Location.Location.Core
347
348| Name| Value| Description|
349| -------- | -------- | -------- |
350| UNSET | 0x300 | Scenario unspecified.<br>If this option is used, [LocationRequestScenario](#locationrequestscenario) is invalid.|
351| NAVIGATION | 0x301 | Navigation.<br>This option is applicable when your application needs to obtain the real-time location of a mobile device outdoors, such as navigation for driving or walking.<br>In this scenario, GNSS positioning is used to provide location services to ensure the optimal location accuracy of the system.<br>The location result is reported at a minimum interval of 1 second by default.|
352| TRAJECTORY_TRACKING | 0x302 | Trajectory tracking.<br>This option is applicable when your application needs to record user trajectories, for example, the track recording function of sports applications. In this scenario, the GNSS positioning technology is mainly used to ensure the location accuracy.<br>The location result is reported at a minimum interval of 1 second by default.|
353| CAR_HAILING | 0x303 | Ride hailing.<br>This option is applicable when your application needs to obtain the current location of a user who is hailing a taxi.<br>The location result is reported at a minimum interval of 1 second by default.|
354| DAILY_LIFE_SERVICE | 0x304 | Daily life services.<br>This option is applicable when your application only needs the approximate user location for recommendations and push notifications in scenarios such as when the user is browsing news, shopping online, and ordering food.<br>The location result is reported at a minimum interval of 1 second by default.|
355| 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.|
356
357
358## LocationPrivacyType
359
360Defines the privacy statement type.
361
362**System capability**: SystemCapability.Location.Location.Core
363
364**System API**: This is a system API.
365
366| Name| Value| Description|
367| -------- | -------- | -------- |
368| OTHERS | 0 | Other scenarios. Reserved field.|
369| STARTUP | 1 | Privacy statement displayed in the startup wizard. The user needs to choose whether to agree with the statement.|
370| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.|
371
372
373## CountryCodeType
374
375Defines the country code source type.
376
377**System capability**: SystemCapability.Location.Location.Core
378
379| Name| Value| Description|
380| -------- | -------- | -------- |
381| COUNTRY_CODE_FROM_LOCALE | 1 | Country code obtained from the language configuration of the globalization module.|
382| COUNTRY_CODE_FROM_SIM | 2 | Country code obtained from the SIM card.|
383| COUNTRY_CODE_FROM_LOCATION | 3 | Country code obtained using the reverse geocoding function based on the user's location information.|
384| COUNTRY_CODE_FROM_NETWORK | 4 | Country code obtained from the cellular network registration information.|
385
386
387## LocatingRequiredDataType<sup>10+</sup>
388
389Defines the type of the required data of the location service.
390
391**System capability**: SystemCapability.Location.Location.Core
392
393**System API**: This is a system API.
394
395| Name| Value| Description|
396| -------- | -------- | -------- |
397| WIFI  | 1 | Wi-Fi scanning information.|
398| BLUETOOTH | 2 | Bluetooth scanning information.|
399
400
401## geoLocationManager.on('locationChange')
402
403on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Location&gt;): void
404
405Subscribes to location change events with a location request initiated.
406
407**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
408
409**System capability**: SystemCapability.Location.Location.Core
410
411**Parameters**
412
413  | Name| Type| Mandatory| Description|
414  | -------- | -------- | -------- | -------- |
415  | type | string | Yes| Event type. The value **locationChange** indicates a location change.|
416  | request |  [LocationRequest](#locationrequest) | Yes| Location request.|
417  | callback | Callback&lt;[Location](#location)&gt; | Yes| Callback used to receive location change events.|
418
419**Error codes**
420
421For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
422
423| ID| Error Message|
424| -------- | ---------------------------------------- |
425|3301000 | Location service is unavailable.                                            |
426|3301100 | The location switch is off.                                                 |
427|3301200 | Failed to obtain the geographical location.                                       |
428
429**Example**
430
431  ```ts
432  import geoLocationManager from '@ohos.geoLocationManager';
433  import BusinessError from "@ohos.base";
434  let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
435  let locationChange = (location:geoLocationManager.Location):void => {
436      console.log('locationChanger: data: ' + JSON.stringify(location));
437  };
438  try {
439      geoLocationManager.on('locationChange', requestInfo, locationChange);
440  } catch (err) {
441      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
442  }
443
444  ```
445
446
447## geoLocationManager.off('locationChange')
448
449off(type: 'locationChange', callback?: Callback&lt;Location&gt;): void
450
451Unsubscribes from location change events with the corresponding location request deleted.
452
453**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
454
455**System capability**: SystemCapability.Location.Location.Core
456
457**Parameters**
458
459  | Name| Type| Mandatory| Description|
460  | -------- | -------- | -------- | -------- |
461  | type | string | Yes| Event type. The value **locationChange** indicates a location change.|
462  | callback | Callback&lt;[Location](#location)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
463
464**Error codes**
465
466For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
467
468| ID| Error Message|
469| -------- | ---------------------------------------- |
470|3301000 | Location service is unavailable.                                            |
471|3301100 | The location switch is off.                                                 |
472|3301200 | Failed to obtain the geographical location.                                       |
473
474**Example**
475
476  ```ts
477  import geoLocationManager from '@ohos.geoLocationManager';
478  import BusinessError from "@ohos.base";
479  let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
480  let locationChange = (location:geoLocationManager.Location):void => {
481    console.log('locationChanger: data: ' + JSON.stringify(location));
482  };
483  try {
484      geoLocationManager.on('locationChange', requestInfo, locationChange);
485      geoLocationManager.off('locationChange', locationChange);
486  } catch (err) {
487      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
488  }
489  ```
490
491
492## geoLocationManager.on('locationEnabledChange')
493
494on(type: 'locationEnabledChange', callback: Callback&lt;boolean&gt;): void
495
496Subscribes to location service status change events.
497
498**System capability**: SystemCapability.Location.Location.Core
499
500**Parameters**
501
502  | Name| Type| Mandatory| Description|
503  | -------- | -------- | -------- | -------- |
504  | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change.|
505  | callback | Callback&lt;boolean&gt; | Yes| Callback used to receive location service status change events.|
506
507**Error codes**
508
509For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
510
511| ID| Error Message|
512| -------- | ---------------------------------------- |
513|3301000 | Location service is unavailable.                                            |
514
515**Example**
516
517  ```ts
518  import geoLocationManager from '@ohos.geoLocationManager';
519  import BusinessError from "@ohos.base";
520  let locationEnabledChange = (state:boolean):void => {
521      console.log('locationEnabledChange: ' + JSON.stringify(state));
522  }
523  try {
524      geoLocationManager.on('locationEnabledChange', locationEnabledChange);
525  } catch (err) {
526      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
527  }
528  ```
529
530
531## geoLocationManager.off('locationEnabledChange')
532
533off(type: 'locationEnabledChange', callback?: Callback&lt;boolean&gt;): void;
534
535Unsubscribes from location service status change events.
536
537**System capability**: SystemCapability.Location.Location.Core
538
539**Parameters**
540
541  | Name| Type| Mandatory| Description|
542  | -------- | -------- | -------- | -------- |
543  | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change.|
544  | callback | Callback&lt;boolean&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
545
546**Error codes**
547
548For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
549
550| ID| Error Message|
551| -------- | ---------------------------------------- |
552|3301000 | Location service is unavailable.                                            |
553
554**Example**
555
556  ```ts
557  import geoLocationManager from '@ohos.geoLocationManager';
558  import BusinessError from "@ohos.base";
559  let locationEnabledChange = (state:boolean):void => {
560      console.log('locationEnabledChange: state: ' + JSON.stringify(state));
561  }
562  try {
563      geoLocationManager.on('locationEnabledChange', locationEnabledChange);
564      geoLocationManager.off('locationEnabledChange', locationEnabledChange);
565  } catch (err) {
566      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
567  }
568  ```
569
570
571## geoLocationManager.on('cachedGnssLocationsChange')
572
573on(type: 'cachedGnssLocationsChange', request: CachedGnssLocationsRequest, callback: Callback&lt;Array&lt;Location&gt;&gt;): void;
574
575Subscribes to cached GNSS location reports. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported.
576
577**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
578
579**System capability**: SystemCapability.Location.Location.Gnss
580
581**Parameters**
582
583  | Name| Type| Mandatory| Description|
584  | -------- | -------- | -------- | -------- |
585  | type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.|
586  | request |  [CachedGnssLocationsRequest](#cachedgnsslocationsrequest) | Yes| Request for reporting cached GNSS location.|
587  | callback | Callback&lt;Array&lt;Location&gt;&gt; | Yes| Callback used to receive cached GNSS locations.|
588
589**Error codes**
590
591For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
592
593| ID| Error Message|
594| -------- | ---------------------------------------- |
595|3301000 | Location service is unavailable.                                            |
596|3301100 | The location switch is off.                                                 |
597|3301200 | Failed to obtain the geographical location.                                       |
598
599**Example**
600
601  ```ts
602  import geoLocationManager from '@ohos.geoLocationManager';
603  import BusinessError from "@ohos.base";
604  let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => {
605      console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
606  }
607  let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
608  try {
609      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
610  } catch (err) {
611      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
612  }
613  ```
614
615
616## geoLocationManager.off('cachedGnssLocationsChange')
617
618off(type: 'cachedGnssLocationsChange', callback?: Callback&lt;Array&lt;Location&gt;&gt;): void;
619
620Unsubscribes from cached GNSS location reports. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported.
621
622**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
623
624**System capability**: SystemCapability.Location.Location.Gnss
625
626**Parameters**
627
628  | Name| Type| Mandatory| Description|
629  | -------- | -------- | -------- | -------- |
630  | type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.|
631  | callback | Callback&lt;Array&lt;Location&gt;&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
632
633**Error codes**
634
635For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
636
637| ID| Error Message|
638| -------- | ---------------------------------------- |
639|3301000 | Location service is unavailable.                                            |
640|3301100 | The location switch is off.                                                 |
641|3301200 | Failed to obtain the geographical location.                                       |
642
643**Example**
644
645  ```ts
646  import geoLocationManager from '@ohos.geoLocationManager';
647  import BusinessError from "@ohos.base";
648  let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => {
649      console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
650  }
651  let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
652  try {
653      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
654      geoLocationManager.off('cachedGnssLocationsChange');
655  } catch (err) {
656      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
657  }
658  ```
659
660
661## geoLocationManager.on('satelliteStatusChange')
662
663on(type: 'satelliteStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;): void;
664
665Subscribes to GNSS satellite status change events.
666
667**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
668
669**System capability**: SystemCapability.Location.Location.Gnss
670
671**Parameters**
672
673  | Name| Type| Mandatory| Description|
674  | -------- | -------- | -------- | -------- |
675  | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change.|
676  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | Yes| Callback used to receive GNSS satellite status change events.|
677
678**Error codes**
679
680For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
681
682| ID| Error Message|
683| -------- | ---------------------------------------- |
684|3301000 | Location service is unavailable.                                            |
685|3301100 | The location switch is off.                                                 |
686
687**Example**
688
689  ```ts
690  import geoLocationManager from '@ohos.geoLocationManager';
691  import BusinessError from "@ohos.base";
692  let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => {
693      console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
694  }
695
696  try {
697      geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
698  } catch (err) {
699      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
700  }
701  ```
702
703
704## geoLocationManager.off('satelliteStatusChange')
705
706off(type: 'satelliteStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;): void;
707
708Unsubscribes from GNSS satellite status change events.
709
710**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
711
712**System capability**: SystemCapability.Location.Location.Gnss
713
714**Parameters**
715
716  | Name| Type| Mandatory| Description|
717  | -------- | -------- | -------- | -------- |
718  | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change.|
719  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
720
721**Error codes**
722
723For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
724
725| ID| Error Message|
726| -------- | ---------------------------------------- |
727|3301000 | Location service is unavailable.                                            |
728|3301100 | The location switch is off.                                                 |
729
730
731**Example**
732
733  ```ts
734  import geoLocationManager from '@ohos.geoLocationManager';
735  import BusinessError from "@ohos.base";
736  let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => {
737      console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
738  }
739  try {
740      geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
741      geoLocationManager.off('satelliteStatusChange', gnssStatusCb);
742  } catch (err) {
743      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
744  }
745  ```
746
747
748## geoLocationManager.on('nmeaMessage')
749
750on(type: 'nmeaMessage', callback: Callback&lt;string&gt;): void;
751
752Subscribes to GNSS NMEA message change events.
753
754**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
755
756**System capability**: SystemCapability.Location.Location.Gnss
757
758**Parameters**
759
760  | Name| Type| Mandatory| Description|
761  | -------- | -------- | -------- | -------- |
762  | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change.|
763  | callback | Callback&lt;string&gt; | Yes| Callback used to receive GNSS NMEA message change events.|
764
765**Error codes**
766
767For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
768
769| ID| Error Message|
770| -------- | ---------------------------------------- |
771|3301000 | Location service is unavailable.                                            |
772|3301100 | The location switch is off.                                                 |
773
774
775**Example**
776
777  ```ts
778  import geoLocationManager from '@ohos.geoLocationManager';
779  import BusinessError from "@ohos.base";
780  let nmeaCb = (str:string):void => {
781      console.log('nmeaMessage: ' + JSON.stringify(str));
782  }
783
784  try {
785      geoLocationManager.on('nmeaMessage', nmeaCb );
786  } catch (err) {
787      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
788  }
789  ```
790
791
792## geoLocationManager.off('nmeaMessage')
793
794off(type: 'nmeaMessage', callback?: Callback&lt;string&gt;): void;
795
796Unsubscribes from GNSS NMEA message change events.
797
798**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
799
800**System capability**: SystemCapability.Location.Location.Gnss
801
802**Parameters**
803
804  | Name| Type| Mandatory| Description|
805  | -------- | -------- | -------- | -------- |
806  | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change.|
807  | callback | Callback&lt;string&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
808
809**Error codes**
810
811For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
812
813| ID| Error Message|
814| -------- | ---------------------------------------- |
815|3301000 | Location service is unavailable.                                            |
816|3301100 | The location switch is off.                                                 |
817
818
819**Example**
820
821  ```ts
822  import geoLocationManager from '@ohos.geoLocationManager';
823  import BusinessError from "@ohos.base";
824  let nmeaCb = (str:string):void => {
825      console.log('nmeaMessage: ' + JSON.stringify(str));
826  }
827
828  try {
829      geoLocationManager.on('nmeaMessage', nmeaCb);
830      geoLocationManager.off('nmeaMessage', nmeaCb);
831  } catch (err) {
832      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
833  }
834  ```
835
836
837## geoLocationManager.on('gnssFenceStatusChange')
838
839on(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
840
841Subscribes to status change events of the specified geofence. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported.
842
843**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
844
845**System capability**: SystemCapability.Location.Location.Geofence
846
847**Parameters**
848
849  | Name| Type| Mandatory| Description|
850  | -------- | -------- | -------- | -------- |
851  | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.|
852  | request |  [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
853  | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
854
855**Error codes**
856
857For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
858
859| ID| Error Message|
860| -------- | ---------------------------------------- |
861|3301000 | Location service is unavailable.                                            |
862|3301100 | The location switch is off.                                                 |
863|3301600 | Failed to operate the geofence.                                     |
864
865**Example**
866
867  ```ts
868  import geoLocationManager from '@ohos.geoLocationManager';
869  import wantAgent from '@ohos.app.ability.wantAgent';
870  import BusinessError from "@ohos.base";
871
872  let wantAgentInfo:wantAgent.WantAgentInfo = {
873      wants: [
874          {
875              bundleName: "com.example.myapplication",
876              abilityName: "EntryAbility",
877              action: "action1"
878          }
879      ],
880      operationType: wantAgent.OperationType.START_ABILITY,
881      requestCode: 0,
882      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
883  };
884
885  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
886    let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
887    try {
888        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
889    } catch (err) {
890        console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
891    }
892  });
893  ```
894
895
896## geoLocationManager.off('gnssFenceStatusChange')
897
898off(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
899
900Unsubscribes from status change events of the specified geofence. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported.
901
902**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
903
904**System capability**: SystemCapability.Location.Location.Geofence
905
906**Parameters**
907
908  | Name| Type| Mandatory| Description|
909  | -------- | -------- | -------- | -------- |
910  | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.|
911  | request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
912  | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
913
914**Error codes**
915
916For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
917
918| ID| Error Message|
919| -------- | ---------------------------------------- |
920|3301000 | Location service is unavailable.                                            |
921|3301100 | The location switch is off.                                                 |
922|3301600 | Failed to operate the geofence.                                     |
923
924**Example**
925
926  ```ts
927  import geoLocationManager from '@ohos.geoLocationManager';
928  import wantAgent from '@ohos.app.ability.wantAgent';
929  import BusinessError from "@ohos.base";
930
931  let wantAgentInfo:wantAgent.WantAgentInfo = {
932      wants: [
933          {
934              bundleName: "com.example.myapplication",
935              abilityName: "EntryAbility",
936              action: "action1",
937          }
938      ],
939      operationType: wantAgent.OperationType.START_ABILITY,
940      requestCode: 0,
941      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
942  };
943
944  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
945    let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};;
946    try {
947        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
948        geoLocationManager.off('gnssFenceStatusChange', requestInfo, wantAgentObj);
949    } catch (err) {
950        console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
951    }
952  });
953  ```
954
955
956## geoLocationManager.on('countryCodeChange')
957
958on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;): void;
959
960Subscribes to country code change events.
961
962**System capability**: SystemCapability.Location.Location.Core
963
964**Parameters**
965
966  | Name| Type| Mandatory| Description|
967  | -------- | -------- | -------- | -------- |
968  | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change.|
969  | callback | Callback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to receive country code change events.|
970
971**Error codes**
972
973For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
974
975| ID| Error Message|
976| -------- | ---------------------------------------- |
977|3301000 | Location service is unavailable.                                            |
978|3301500 | Failed to query the area information.                                       |
979
980
981**Example**
982
983  ```ts
984  import geoLocationManager from '@ohos.geoLocationManager';
985  import BusinessError from "@ohos.base";
986  let callback = (code:geoLocationManager.CountryCode):void => {
987      console.log('countryCodeChange: ' + JSON.stringify(code));
988  }
989
990  try {
991      geoLocationManager.on('countryCodeChange', callback);
992  } catch (err) {
993      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
994  }
995  ```
996
997
998## geoLocationManager.off('countryCodeChange')
999
1000off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;): void;
1001
1002Unsubscribes from country code change events.
1003
1004**System capability**: SystemCapability.Location.Location.Core
1005
1006**Parameters**
1007
1008  | Name| Type| Mandatory| Description|
1009  | -------- | -------- | -------- | -------- |
1010  | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change.|
1011  | callback | Callback&lt;[CountryCode](#countrycode)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
1012
1013**Error codes**
1014
1015For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1016
1017| ID| Error Message|
1018| -------- | ---------------------------------------- |
1019|3301000 | Location service is unavailable.                                            |
1020|3301500 | Failed to query the area information.                                       |
1021
1022**Example**
1023
1024  ```ts
1025  import geoLocationManager from '@ohos.geoLocationManager';
1026  import BusinessError from "@ohos.base";
1027  let callback = (code:geoLocationManager.CountryCode):void => {
1028      console.log('countryCodeChange: ' + JSON.stringify(code));
1029  }
1030
1031  try {
1032      geoLocationManager.on('countryCodeChange', callback);
1033      geoLocationManager.off('countryCodeChange', callback);
1034  } catch (err) {
1035      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1036  }
1037  ```
1038
1039
1040## geoLocationManager.on('locatingRequiredDataChange')<sup>10+</sup>
1041
1042on(type: 'locatingRequiredDataChange', config: LocatingRequiredDataConfig, callback: Callback&lt;Array&lt;LocatingRequiredData&gt;&gt;): void;
1043
1044Subscribes 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.
1045
1046**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
1047
1048**System capability**: SystemCapability.Location.Location.Core
1049
1050**System API**: This is a system API.
1051
1052**Parameters**
1053
1054  | Name| Type| Mandatory| Description|
1055  | -------- | -------- | -------- | -------- |
1056  | type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.|
1057  | config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.|
1058  | callback | Callback&lt;Array&lt;[LocatingRequiredData](#locatingrequireddata10)&gt;&gt; | Yes| Callback used to receive the required data of the location service.|
1059
1060**Error codes**
1061
1062For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1063
1064| ID| Error Message|
1065| -------- | ---------------------------------------- |
1066|3301800 | Failed to start WiFi or Bluetooth scanning.                            |
1067
1068**Example**
1069
1070  ```ts
1071  import geoLocationManager from '@ohos.geoLocationManager';
1072  import BusinessError from "@ohos.base";
1073  let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => {
1074      console.log('locatingRequiredDataChange: ' + JSON.stringify(code));
1075  }
1076  let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
1077  try {
1078      geoLocationManager.on('locatingRequiredDataChange', config, callback);
1079  } catch (err) {
1080      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1081  }
1082  ```
1083
1084
1085## geoLocationManager.off('locatingRequiredDataChange')<sup>10+</sup>
1086
1087off(type: 'locatingRequiredDataChange', callback?: Callback&lt;Array&lt;LocatingRequiredData&gt;&gt;): void;
1088
1089Unsubscribes from changes in the required data of the location service and stops Wi-Fi and Bluetooth scanning.
1090
1091**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
1092
1093**System capability**: SystemCapability.Location.Location.Core
1094
1095**System API**: This is a system API.
1096
1097**Parameters**
1098
1099  | Name| Type| Mandatory| Description|
1100  | -------- | -------- | -------- | -------- |
1101  | type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.|
1102  | callback | Callback&lt;Array&lt;[LocatingRequiredData](#locatingrequireddata10)&gt;&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
1103
1104**Error codes**
1105
1106For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1107
1108**Example**
1109
1110  ```ts
1111  import geoLocationManager from '@ohos.geoLocationManager';
1112  import BusinessError from "@ohos.base";
1113  let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => {
1114      console.log('locatingRequiredDataChange: ' + JSON.stringify(code));
1115  }
1116  let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
1117  try {
1118      geoLocationManager.on('locatingRequiredDataChange', config, callback);
1119      geoLocationManager.off('locatingRequiredDataChange', callback);
1120  } catch (err) {
1121      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1122  }
1123  ```
1124
1125
1126## geoLocationManager.getCurrentLocation
1127
1128getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;Location&gt;): void
1129
1130Obtains the current location. This API uses an asynchronous callback to return the result.
1131
1132**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
1133
1134**System capability**: SystemCapability.Location.Location.Core
1135
1136**Parameters**
1137
1138  | Name| Type| Mandatory| Description|
1139  | -------- | -------- | -------- | -------- |
1140  | request | [CurrentLocationRequest](#currentlocationrequest) | Yes| Location request.|
1141  | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to receive the current location.|
1142
1143**Error codes**
1144
1145For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1146
1147| ID| Error Message|
1148| -------- | ---------------------------------------- |
1149|3301000 | Location service is unavailable.                                            |
1150|3301100 | The location switch is off.                                                 |
1151|3301200 | Failed to obtain the geographical location.  |
1152
1153**Example**
1154
1155  ```ts
1156  import geoLocationManager from '@ohos.geoLocationManager';
1157  import BusinessError from "@ohos.base";
1158  let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
1159  let locationChange = (err:BusinessError.BusinessError, location:geoLocationManager.Location):void => {
1160      if (err) {
1161          console.error('locationChanger: err=' + JSON.stringify(err));
1162      }
1163      if (location) {
1164          console.log('locationChanger: location=' + JSON.stringify(location));
1165      }
1166  };
1167
1168  try {
1169      geoLocationManager.getCurrentLocation(requestInfo, locationChange);
1170  } catch (err) {
1171      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1172  }
1173  ```
1174
1175## geoLocationManager.getCurrentLocation
1176
1177getCurrentLocation(callback: AsyncCallback&lt;Location&gt;): void;
1178
1179Obtains the current location. This API uses an asynchronous callback to return the result.
1180
1181**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
1182
1183**System capability**: SystemCapability.Location.Location.Core
1184
1185**Parameters**
1186
1187  | Name| Type| Mandatory| Description|
1188  | -------- | -------- | -------- | -------- |
1189  | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to receive the current location.|
1190
1191**Error codes**
1192
1193For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1194
1195| ID| Error Message|
1196| -------- | ---------------------------------------- |
1197|3301000 | Location service is unavailable.                                            |
1198|3301100 | The location switch is off.                                                 |
1199|3301200 | Failed to obtain the geographical location.  |
1200
1201**Example**
1202
1203  ```ts
1204  import geoLocationManager from '@ohos.geoLocationManager';
1205  import BusinessError from "@ohos.base";
1206  let locationChange = (err:BusinessError.BusinessError, location:geoLocationManager.Location) => {
1207      if (err) {
1208          console.error('locationChanger: err=' + JSON.stringify(err));
1209      }
1210      if (location) {
1211          console.log('locationChanger: location=' + JSON.stringify(location));
1212      }
1213  };
1214
1215  try {
1216      geoLocationManager.getCurrentLocation(locationChange);
1217  } catch (err) {
1218      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1219  }
1220  ```
1221
1222## geoLocationManager.getCurrentLocation
1223
1224getCurrentLocation(request?: CurrentLocationRequest): Promise&lt;Location&gt;
1225
1226Obtains the current location. This API uses a promise to return the result.
1227
1228**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
1229
1230**System capability**: SystemCapability.Location.Location.Core
1231
1232**Parameters**
1233
1234  | Name| Type| Mandatory| Description|
1235  | -------- | -------- | -------- | -------- |
1236  | request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.|
1237
1238**Return value**
1239
1240  | Type| Description|
1241  | -------- | -------- |
1242  | [Location](#location) | Promise used to return the current location.|
1243
1244**Error codes**
1245
1246For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1247
1248| ID| Error Message|
1249| -------- | ---------------------------------------- |
1250|3301000 | Location service is unavailable.                                            |
1251|3301100 | The location switch is off.                                                 |
1252|3301200 | Failed to obtain the geographical location.  |
1253
1254**Example**
1255
1256  ```ts
1257  import geoLocationManager from '@ohos.geoLocationManager';
1258  import BusinessError from "@ohos.base";
1259  let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
1260  try {
1261      geoLocationManager.getCurrentLocation(requestInfo).then((result) => {
1262          console.log('current location: ' + JSON.stringify(result));
1263      })
1264      .catch((error:number) => {
1265          console.error('promise, getCurrentLocation: error=' + JSON.stringify(error));
1266      });
1267  } catch (err) {
1268      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1269  }
1270  ```
1271
1272
1273## geoLocationManager.getLastLocation
1274
1275getLastLocation(): Location
1276
1277Obtains the last location.
1278
1279**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
1280
1281**System capability**: SystemCapability.Location.Location.Core
1282
1283**Return value**
1284
1285  | Type| Description|
1286  | -------- | -------- |
1287  | [Location](#location) | Location information.|
1288
1289**Error codes**
1290
1291For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1292
1293| ID| Error Message|
1294| -------- | ---------------------------------------- |
1295|3301000 | Location service is unavailable.  |
1296|3301100 | The location switch is off.  |
1297|3301200 |Failed to obtain the geographical location.  |
1298
1299**Example**
1300
1301  ```ts
1302  import geoLocationManager from '@ohos.geoLocationManager';
1303  import BusinessError from "@ohos.base";
1304  try {
1305      let location = geoLocationManager.getLastLocation();
1306  } catch (err) {
1307      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1308  }
1309  ```
1310
1311
1312## geoLocationManager.isLocationEnabled
1313
1314isLocationEnabled(): boolean
1315
1316Checks whether the location service is enabled.
1317
1318**System capability**: SystemCapability.Location.Location.Core
1319
1320**Return value**
1321
1322  | Type| Description|
1323  | -------- | -------- |
1324  | boolean | Result indicating whether the location service is enabled.|
1325
1326**Error codes**
1327
1328For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1329
1330| ID| Error Message|
1331| -------- | ---------------------------------------- |
1332|3301000 | Location service is unavailable.  |
1333
1334**Example**
1335
1336  ```ts
1337  import geoLocationManager from '@ohos.geoLocationManager';
1338  import BusinessError from "@ohos.base";
1339  try {
1340      let locationEnabled = geoLocationManager.isLocationEnabled();
1341  } catch (err) {
1342      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1343  }
1344  ```
1345
1346
1347## geoLocationManager.enableLocation
1348
1349enableLocation(callback: AsyncCallback&lt;void&gt;): void;
1350
1351Enables the location service. This API uses an asynchronous callback to return the result.
1352
1353**System API**: This is a system API.
1354
1355**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
1356
1357**System capability**: SystemCapability.Location.Location.Core
1358
1359**Parameters**
1360
1361  | Name| Type| Mandatory| Description|
1362  | -------- | -------- | -------- | -------- |
1363  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to receive the error message.|
1364
1365**Error codes**
1366
1367For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1368
1369| ID| Error Message|
1370| -------- | ---------------------------------------- |
1371|3301000 | Location service is unavailable.                                            |
1372
1373**Example**
1374
1375  ```ts
1376  import geoLocationManager from '@ohos.geoLocationManager';
1377  import BusinessError from "@ohos.base";
1378  try {
1379      geoLocationManager.enableLocation((err) => {
1380          if (err) {
1381              console.error('enableLocation: err=' + JSON.stringify(err));
1382          }
1383      });
1384  } catch (err) {
1385      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1386  }
1387  ```
1388
1389
1390## geoLocationManager.enableLocation
1391
1392enableLocation(): Promise&lt;void&gt;
1393
1394Enables the location service. This API uses a promise to return the result.
1395
1396**System API**: This is a system API.
1397
1398**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
1399
1400**System capability**: SystemCapability.Location.Location.Core
1401
1402**Return value**
1403
1404  | Type| Description|
1405  | -------- | -------- |
1406  | void | No value is returned.|
1407
1408**Error codes**
1409
1410For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1411
1412| ID| Error Message|
1413| -------- | ---------------------------------------- |
1414|3301000 | Location service is unavailable.                                            |
1415
1416**Example**
1417
1418  ```ts
1419  import geoLocationManager from '@ohos.geoLocationManager';
1420  import BusinessError from "@ohos.base";
1421  try {
1422      geoLocationManager.enableLocation().then(() => {
1423          console.log('promise, enableLocation succeed');
1424      })
1425      .catch((error:number) => {
1426          console.error('promise, enableLocation: error=' + JSON.stringify(error));
1427      });
1428  } catch (err) {
1429      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1430  }
1431  ```
1432
1433## geoLocationManager.disableLocation
1434
1435disableLocation(): void;
1436
1437Disables the location service.
1438
1439**System API**: This is a system API.
1440
1441**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
1442
1443**System capability**: SystemCapability.Location.Location.Core
1444
1445**Error codes**
1446
1447For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1448
1449| ID| Error Message|
1450| -------- | ---------------------------------------- |
1451|3301000 | Location service is unavailable.                                            |
1452
1453**Example**
1454
1455  ```ts
1456  import geoLocationManager from '@ohos.geoLocationManager';
1457  import BusinessError from "@ohos.base";
1458  try {
1459      geoLocationManager.disableLocation();
1460  } catch (err) {
1461      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1462  }
1463  ```
1464
1465
1466## geoLocationManager.getAddressesFromLocation
1467
1468getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
1469
1470Converts coordinates into geographic description through reverse geocoding. This API uses an asynchronous callback to return the result.
1471
1472**System capability**: SystemCapability.Location.Location.Geocoder
1473
1474**Parameters**
1475
1476  | Name| Type| Mandatory| Description|
1477  | -------- | -------- | -------- | -------- |
1478  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
1479  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to receive the reverse geocoding result.|
1480
1481**Error codes**
1482
1483For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1484
1485| ID| Error Message|
1486| -------- | ---------------------------------------- |
1487|3301000 | Location service is unavailable.   |
1488|3301300 | Reverse geocoding query failed.   |
1489
1490**Example**
1491
1492  ```ts
1493  import geoLocationManager from '@ohos.geoLocationManager';
1494  import BusinessError from "@ohos.base";
1495  let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
1496  try {
1497      geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
1498          if (err) {
1499              console.error('getAddressesFromLocation: err=' + JSON.stringify(err));
1500          }
1501          if (data) {
1502              console.log('getAddressesFromLocation: data=' + JSON.stringify(data));
1503          }
1504      });
1505  } catch (err) {
1506      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1507  }
1508  ```
1509
1510
1511## geoLocationManager.getAddressesFromLocation
1512
1513getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;;
1514
1515Converts coordinates into geographic description through reverse geocoding. This API uses a promise to return the result.
1516
1517**System capability**: SystemCapability.Location.Location.Geocoder
1518
1519**Parameters**
1520
1521  | Name| Type| Mandatory| Description|
1522  | -------- | -------- | -------- | -------- |
1523  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
1524
1525**Return value**
1526
1527  | Type| Description|
1528  | -------- | -------- |
1529  | Array&lt;[GeoAddress](#geoaddress)&gt; | Promise used to return the reverse geocoding result.|
1530
1531**Error codes**
1532
1533For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1534
1535| ID| Error Message|
1536| -------- | ---------------------------------------- |
1537|3301000 | Location service is unavailable.   |
1538|3301300 | Reverse geocoding query failed.   |
1539
1540**Example**
1541
1542  ```ts
1543  import geoLocationManager from '@ohos.geoLocationManager';
1544  import BusinessError from "@ohos.base";
1545  let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
1546  try {
1547      geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
1548          console.log('getAddressesFromLocation: ' + JSON.stringify(data));
1549      })
1550      .catch((error:number) => {
1551          console.error('promise, getAddressesFromLocation: error=' + JSON.stringify(error));
1552      });
1553  } catch (err) {
1554      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1555  }
1556  ```
1557
1558
1559## geoLocationManager.getAddressesFromLocationName
1560
1561getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
1562
1563Converts geographic description into coordinates through geocoding. This API uses an asynchronous callback to return the result.
1564
1565**System capability**: SystemCapability.Location.Location.Geocoder
1566
1567**Parameters**
1568
1569  | Name| Type| Mandatory| Description|
1570  | -------- | -------- | -------- | -------- |
1571  | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
1572  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to receive the geocoding result.|
1573
1574**Error codes**
1575
1576For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1577
1578| ID| Error Message|
1579| -------- | ---------------------------------------- |
1580|3301000 | Location service is unavailable.   |
1581|3301400 | Geocoding query failed.   |
1582
1583**Example**
1584
1585  ```ts
1586  import geoLocationManager from '@ohos.geoLocationManager';
1587  import BusinessError from "@ohos.base";
1588  let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
1589  try {
1590      geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => {
1591          if (err) {
1592              console.error('getAddressesFromLocationName: err=' + JSON.stringify(err));
1593          }
1594          if (data) {
1595              console.log('getAddressesFromLocationName: data=' + JSON.stringify(data));
1596          }
1597      });
1598  } catch (err) {
1599      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1600  }
1601  ```
1602
1603
1604## geoLocationManager.getAddressesFromLocationName
1605
1606getAddressesFromLocationName(request: GeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;
1607
1608Converts geographic description into coordinates through geocoding. This API uses a promise to return the result.
1609
1610**System capability**: SystemCapability.Location.Location.Geocoder
1611
1612**Parameters**
1613
1614  | Name| Type| Mandatory| Description|
1615  | -------- | -------- | -------- | -------- |
1616  | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
1617
1618**Return value**
1619
1620  | Type| Description|
1621  | -------- | -------- |
1622  | Array&lt;[GeoAddress](#geoaddress)&gt; | Promise used to return the geocoding result.|
1623
1624**Error codes**
1625
1626For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1627
1628| ID| Error Message|
1629| -------- | ---------------------------------------- |
1630|3301000 | Location service is unavailable.   |
1631|3301400 | Geocoding query failed.   |
1632
1633**Example**
1634
1635  ```ts
1636  import geoLocationManager from '@ohos.geoLocationManager';
1637  import BusinessError from "@ohos.base";
1638  let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
1639  try {
1640      geoLocationManager.getAddressesFromLocationName(geocodeRequest).then((result) => {
1641          console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
1642      })
1643      .catch((error:number) => {
1644          console.error('promise, getAddressesFromLocationName: error=' + JSON.stringify(error));
1645      });
1646  } catch (err) {
1647      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1648  }
1649  ```
1650
1651## geoLocationManager.isGeocoderAvailable
1652
1653isGeocoderAvailable(): boolean;
1654
1655Obtains the (reverse) geocoding service status.
1656
1657**System capability**: SystemCapability.Location.Location.Geocoder
1658
1659**Return value**
1660
1661  | Type| Description|
1662  | -------- | -------- |
1663  | boolean | Result indicating whether the (reverse) geocoding service is available.|
1664
1665**Error codes**
1666
1667For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1668
1669| ID| Error Message|
1670| -------- | ---------------------------------------- |
1671|3301000 | Location service is unavailable.   |
1672
1673**Example**
1674
1675  ```ts
1676  import geoLocationManager from '@ohos.geoLocationManager';
1677  import BusinessError from "@ohos.base";
1678  try {
1679      let isAvailable = geoLocationManager.isGeocoderAvailable();
1680  } catch (err) {
1681      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1682  }
1683  ```
1684
1685
1686## geoLocationManager.getCachedGnssLocationsSize
1687
1688getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;): void;
1689
1690Obtains the number of cached GNSS locations. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported.
1691
1692**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
1693
1694**System capability**: SystemCapability.Location.Location.Gnss
1695
1696**Parameters**
1697
1698  | Name| Type| Mandatory| Description|
1699  | -------- | -------- | -------- | -------- |
1700  | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to receive the number of cached GNSS locations. |
1701
1702**Error codes**
1703
1704For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1705
1706| ID| Error Message|
1707| -------- | ---------------------------------------- |
1708|3301000 | Location service is unavailable.   |
1709|3301100 | The location switch is off.   |
1710
1711**Example**
1712
1713  ```ts
1714  import geoLocationManager from '@ohos.geoLocationManager';
1715  import BusinessError from "@ohos.base";
1716  try {
1717      geoLocationManager.getCachedGnssLocationsSize((err, size) => {
1718          if (err) {
1719              console.error('getCachedGnssLocationsSize: err=' + JSON.stringify(err));
1720          }
1721          if (size) {
1722              console.log('getCachedGnssLocationsSize: size=' + JSON.stringify(size));
1723          }
1724      });
1725  } catch (err) {
1726      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1727  }
1728  ```
1729
1730
1731## geoLocationManager.getCachedGnssLocationsSize
1732
1733getCachedGnssLocationsSize(): Promise&lt;number&gt;;
1734
1735Obtains the number of cached GNSS locations. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported.
1736
1737**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
1738
1739**System capability**: SystemCapability.Location.Location.Gnss
1740
1741**Return value**
1742
1743  | Type| Description|
1744  | -------- | -------- |
1745  | number | Promise used to return the number of cached GNSS locations.|
1746
1747**Error codes**
1748
1749For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1750
1751| ID| Error Message|
1752| -------- | ---------------------------------------- |
1753|3301000 | Location service is unavailable.   |
1754|3301100 | The location switch is off.   |
1755
1756**Example**
1757
1758  ```ts
1759  import geoLocationManager from '@ohos.geoLocationManager';
1760  import BusinessError from "@ohos.base";
1761  try {
1762      geoLocationManager.getCachedGnssLocationsSize().then((result) => {
1763          console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
1764      })
1765      .catch((error:number) => {
1766          console.error('promise, getCachedGnssLocationsSize: error=' + JSON.stringify(error));
1767      });
1768  } catch (err) {
1769      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1770  }
1771  ```
1772
1773
1774## geoLocationManager.flushCachedGnssLocations
1775
1776flushCachedGnssLocations(callback: AsyncCallback&lt;void&gt;): void;
1777
1778Obtains all cached GNSS locations and clears the GNSS cache queue. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported.
1779
1780**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
1781
1782**System capability**: SystemCapability.Location.Location.Gnss
1783
1784**Parameters**
1785
1786  | Name| Type| Mandatory| Description|
1787  | -------- | -------- | -------- | -------- |
1788  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to receive the error message.|
1789
1790**Error codes**
1791
1792For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1793
1794| ID| Error Message|
1795| -------- | ---------------------------------------- |
1796|3301000 | Location service is unavailable.   |
1797|3301100 | The location switch is off.   |
1798|3301200 | Failed to obtain the geographical location.   |
1799
1800**Example**
1801
1802  ```ts
1803  import geoLocationManager from '@ohos.geoLocationManager';
1804  import BusinessError from "@ohos.base";
1805  try {
1806      geoLocationManager.flushCachedGnssLocations((err) => {
1807          if (err) {
1808              console.error('flushCachedGnssLocations: err=' + JSON.stringify(err));
1809          }
1810      });
1811  } catch (err) {
1812      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1813  }
1814  ```
1815
1816
1817## geoLocationManager.flushCachedGnssLocations
1818
1819flushCachedGnssLocations(): Promise&lt;void&gt;;
1820
1821Obtains all cached GNSS locations and clears the GNSS cache queue. This API is supported only by certain GNSS chip models. If the required chip model is not available, error code 801 (Capability not supported) will be reported.
1822
1823**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
1824
1825**System capability**: SystemCapability.Location.Location.Gnss
1826
1827**Return value**
1828
1829  | Type| Description|
1830  | -------- | -------- |
1831  | void | No value is returned.|
1832
1833**Error codes**
1834
1835For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1836
1837| ID| Error Message|
1838| -------- | ---------------------------------------- |
1839|3301000 | Location service is unavailable.   |
1840|3301100 | The location switch is off.   |
1841|3301200 | Failed to obtain the geographical location.   |
1842
1843**Example**
1844
1845  ```ts
1846  import geoLocationManager from '@ohos.geoLocationManager';
1847  import BusinessError from "@ohos.base";
1848  try {
1849      geoLocationManager.flushCachedGnssLocations().then(() => {
1850          console.log('promise, flushCachedGnssLocations success');
1851      })
1852      .catch((error:number) => {
1853          console.error('promise, flushCachedGnssLocations: error=' + JSON.stringify(error));
1854      });
1855  } catch (err) {
1856      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1857  }
1858  ```
1859
1860
1861## geoLocationManager.sendCommand
1862
1863sendCommand(command: LocationCommand, callback: AsyncCallback&lt;void&gt;): void;
1864
1865Sends an extended command to the location subsystem.
1866
1867**System capability**: SystemCapability.Location.Location.Core
1868
1869**Parameters**
1870
1871  | Name| Type| Mandatory| Description|
1872  | -------- | -------- | -------- | -------- |
1873  | command |  [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
1874  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to receive the error code.|
1875
1876**Error codes**
1877
1878For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1879
1880| ID| Error Message|
1881| -------- | ---------------------------------------- |
1882|3301000 | Location service is unavailable.   |
1883
1884**Example**
1885
1886  ```ts
1887  import geoLocationManager from '@ohos.geoLocationManager';
1888  import BusinessError from "@ohos.base";
1889  let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
1890  try {
1891      geoLocationManager.sendCommand(requestInfo, (err) => {
1892          if (err) {
1893              console.error('sendCommand: err=' + JSON.stringify(err));
1894          }
1895      });
1896  } catch (err) {
1897      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1898  }
1899  ```
1900
1901
1902## geoLocationManager.sendCommand
1903
1904sendCommand(command: LocationCommand): Promise&lt;void&gt;;
1905
1906Sends an extended command to the location subsystem.
1907
1908**System capability**: SystemCapability.Location.Location.Core
1909
1910**Parameters**
1911
1912  | Name| Type| Mandatory| Description|
1913  | -------- | -------- | -------- | -------- |
1914  | command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
1915
1916**Return value**
1917
1918  | Type| Description|
1919  | -------- | -------- |
1920  | void | No value is returned.|
1921
1922**Error codes**
1923
1924For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1925
1926| ID| Error Message|
1927| -------- | ---------------------------------------- |
1928|3301000 | Location service is unavailable.                                            |
1929
1930**Example**
1931
1932  ```ts
1933  import geoLocationManager from '@ohos.geoLocationManager';
1934  import BusinessError from "@ohos.base";
1935  let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
1936  try {
1937      geoLocationManager.sendCommand(requestInfo).then(() => {
1938          console.log('promise, sendCommand success');
1939      })
1940      .catch((error:number) => {
1941          console.error('promise, sendCommand: error=' + JSON.stringify(error));
1942      });
1943  } catch (err) {
1944      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1945  }
1946  ```
1947
1948
1949## geoLocationManager.getCountryCode
1950
1951getCountryCode(callback: AsyncCallback&lt;CountryCode&gt;): void;
1952
1953Obtains the current country code.
1954
1955**System capability**: SystemCapability.Location.Location.Core
1956
1957**Parameters**
1958
1959  | Name| Type| Mandatory| Description|
1960  | -------- | -------- | -------- | -------- |
1961  | callback | AsyncCallback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to receive the country code.|
1962
1963**Error codes**
1964
1965For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
1966
1967| ID| Error Message|
1968| -------- | ---------------------------------------- |
1969|3301000 | Location service is unavailable.                                            |
1970|3301500 | Failed to query the area information.|
1971
1972**Example**
1973
1974  ```ts
1975  import geoLocationManager from '@ohos.geoLocationManager';
1976  import BusinessError from "@ohos.base";
1977  try {
1978      geoLocationManager.getCountryCode((err, result) => {
1979          if (err) {
1980              console.error('getCountryCode: err=' + JSON.stringify(err));
1981          }
1982          if (result) {
1983              console.log('getCountryCode: result=' + JSON.stringify(result));
1984          }
1985      });
1986  } catch (err) {
1987      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
1988  }
1989  ```
1990
1991
1992## geoLocationManager.getCountryCode
1993
1994getCountryCode(): Promise&lt;CountryCode&gt;;
1995
1996Obtains the current country code.
1997
1998**System capability**: SystemCapability.Location.Location.Core
1999
2000**Return value**
2001
2002  | Type| Description|
2003  | -------- | -------- |
2004  | [CountryCode](#countrycode) | Callback used to receive the country code.|
2005
2006**Error codes**
2007
2008For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
2009
2010| ID| Error Message|
2011| -------- | ---------------------------------------- |
2012|3301000 | Location service is unavailable.                                            |
2013|3301500 | Failed to query the area information.|
2014
2015**Example**
2016
2017  ```ts
2018  import geoLocationManager from '@ohos.geoLocationManager';
2019  import BusinessError from "@ohos.base";
2020  try {
2021      geoLocationManager.getCountryCode()
2022      .then((result) => {
2023          console.log('promise, getCountryCode: result=' + JSON.stringify(result));
2024      })
2025      .catch((error:number) => {
2026          console.error('promise, getCountryCode: error=' + JSON.stringify(error));
2027      });
2028  } catch (err) {
2029      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
2030  }
2031  ```
2032
2033
2034## geoLocationManager.enableLocationMock
2035
2036enableLocationMock(): void;
2037
2038Enables the mock location function.
2039
2040**System capability**: SystemCapability.Location.Location.Core
2041
2042**System API**: This is a system API.
2043
2044**Error codes**
2045
2046For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
2047
2048| ID| Error Message|
2049| -------- | ---------------------------------------- |
2050|3301000 | Location service is unavailable.                                            |
2051|3301100 | The location switch is off.|
2052
2053**Example**
2054
2055  ```ts
2056  import geoLocationManager from '@ohos.geoLocationManager';
2057  import BusinessError from "@ohos.base";
2058  try {
2059      geoLocationManager.enableLocationMock();
2060  } catch (err) {
2061      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
2062  }
2063  ```
2064
2065
2066## geoLocationManager.disableLocationMock
2067
2068disableLocationMock(): void;
2069
2070Disables the mock location function.
2071
2072**System capability**: SystemCapability.Location.Location.Core
2073
2074**System API**: This is a system API.
2075
2076**Error codes**
2077
2078For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
2079
2080| ID| Error Message|
2081| -------- | ---------------------------------------- |
2082|3301000 | Location service is unavailable.                                            |
2083|3301100 | The location switch is off.|
2084
2085**Example**
2086
2087  ```ts
2088  import geoLocationManager from '@ohos.geoLocationManager';
2089  import BusinessError from "@ohos.base";
2090  try {
2091      geoLocationManager.disableLocationMock();
2092  } catch (err) {
2093      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
2094  }
2095  ```
2096
2097
2098## geoLocationManager.setMockedLocations
2099
2100setMockedLocations(config: LocationMockConfig): void;
2101
2102Sets the mock location information. The mock locations will be reported at the interval specified in this API.
2103
2104This API can be invoked only after [geoLocationManager.enableLocationMock](#geolocationmanagerenablelocationmock) is called.
2105
2106**System capability**: SystemCapability.Location.Location.Core
2107
2108**System API**: This is a system API.
2109
2110**Parameters**
2111
2112  | Name| Type| Mandatory| Description|
2113  | -------- | -------- | -------- | -------- |
2114  | config |  [LocationMockConfig](#locationmockconfig) | Yes| Mock location information, including the interval for reporting the mock locations and the array of the mock locations.|
2115
2116**Error codes**
2117
2118For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
2119
2120| ID| Error Message|
2121| -------- | ---------------------------------------- |
2122|3301000 | Location service is unavailable.                                            |
2123|3301100 | The location switch is off.|
2124
2125**Example**
2126
2127  ```ts
2128  import geoLocationManager from '@ohos.geoLocationManager';
2129  import BusinessError from "@ohos.base";
2130  let locations:Array<geoLocationManager.Location> = [
2131      {"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true},
2132      {"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true},
2133      {"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true},
2134      {"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true},
2135      {"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true}
2136  ];
2137  let config:geoLocationManager.LocationMockConfig = {"timeInterval": 5, "locations": locations};
2138  try {
2139      geoLocationManager.enableLocationMock();
2140      geoLocationManager.setMockedLocations(config);
2141  } catch (err) {
2142      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
2143  }
2144  ```
2145
2146
2147## geoLocationManager.enableReverseGeocodingMock
2148
2149enableReverseGeocodingMock(): void;
2150
2151Enables the mock reverse geocoding function.
2152
2153**System capability**: SystemCapability.Location.Location.Core
2154
2155**System API**: This is a system API.
2156
2157**Error codes**
2158
2159For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
2160
2161| ID| Error Message|
2162| -------- | ---------------------------------------- |
2163|3301000 | Location service is unavailable.                                            |
2164
2165**Example**
2166
2167  ```ts
2168  import geoLocationManager from '@ohos.geoLocationManager';
2169  import BusinessError from "@ohos.base";
2170  try {
2171      geoLocationManager.enableReverseGeocodingMock();
2172  } catch (err) {
2173      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
2174  }
2175  ```
2176
2177
2178## geoLocationManager.disableReverseGeocodingMock
2179
2180disableReverseGeocodingMock(): void;
2181
2182Disables the mock geocoding function.
2183
2184**System capability**: SystemCapability.Location.Location.Core
2185
2186**System API**: This is a system API.
2187
2188**Error codes**
2189
2190For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
2191
2192| ID| Error Message|
2193| -------- | ---------------------------------------- |
2194|3301000 | Location service is unavailable.                                            |
2195
2196**Example**
2197
2198  ```ts
2199  import geoLocationManager from '@ohos.geoLocationManager';
2200  import BusinessError from "@ohos.base";
2201  try {
2202      geoLocationManager.disableReverseGeocodingMock();
2203  } catch (err) {
2204      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
2205  }
2206  ```
2207
2208
2209## geoLocationManager.setReverseGeocodingMockInfo
2210
2211setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;): void;
2212
2213Sets 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.
2214
2215This API can be invoked only after [geoLocationManager.enableReverseGeocodingMock](#geolocationmanagerenablereversegeocodingmock) is called.
2216
2217**System capability**: SystemCapability.Location.Location.Core
2218
2219**System API**: This is a system API.
2220
2221**Parameters**
2222
2223  | Name| Type| Mandatory| Description|
2224  | -------- | -------- | -------- | -------- |
2225  | mockInfos | Array&lt;[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)&gt; | Yes| Array of information of the mock reverse geocoding function, including a location and a geographical name.|
2226
2227**Error codes**
2228
2229For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
2230
2231| ID| Error Message|
2232| -------- | ---------------------------------------- |
2233|3301000 | Location service is unavailable.                                            |
2234
2235**Example**
2236
2237  ```ts
2238  import geoLocationManager from '@ohos.geoLocationManager';
2239  import BusinessError from "@ohos.base";
2240  let mockInfos:Array<geoLocationManager.ReverseGeocodingMockInfo> = [
2241      {"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "isFromMock": true}},
2242      {"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "isFromMock": true}},
2243      {"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "isFromMock": true}},
2244      {"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "isFromMock": true}},
2245      {"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "isFromMock": true}},
2246  ];
2247  try {
2248      geoLocationManager.enableReverseGeocodingMock();
2249      geoLocationManager.setReverseGeocodingMockInfo(mockInfos);
2250  } catch (err) {
2251      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
2252  }
2253  ```
2254
2255
2256## geoLocationManager.isLocationPrivacyConfirmed
2257
2258isLocationPrivacyConfirmed(type: LocationPrivacyType): boolean;
2259
2260Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications.
2261
2262**System API**: This is a system API.
2263
2264**System capability**: SystemCapability.Location.Location.Core
2265
2266**Parameters**
2267
2268  | Name| Type| Mandatory| Description|
2269  | -------- | -------- | -------- | -------- |
2270  | 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.|
2271
2272**Return value**
2273
2274  | Type| Description|
2275  | -------- | -------- |
2276  | boolean | Whether the user agrees with the privacy statement.|
2277
2278**Error codes**
2279
2280For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
2281
2282| ID| Error Message|
2283| -------- | ---------------------------------------- |
2284|3301000 | Location service is unavailable.                                            |
2285
2286**Example**
2287
2288  ```ts
2289  import geoLocationManager from '@ohos.geoLocationManager';
2290  import BusinessError from "@ohos.base";
2291  try {
2292      let isConfirmed = geoLocationManager.isLocationPrivacyConfirmed(1);
2293  } catch (err) {
2294      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
2295  }
2296  ```
2297
2298
2299## geoLocationManager.setLocationPrivacyConfirmStatus
2300
2301setLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean): void;
2302
2303Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications.
2304
2305**System API**: This is a system API.
2306
2307**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
2308
2309**System capability**: SystemCapability.Location.Location.Core
2310
2311**Parameters**
2312
2313  | Name| Type| Mandatory| Description|
2314  | -------- | -------- | -------- | -------- |
2315  | 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.|
2316  | isConfirmed | boolean | Yes| Whether the user agrees with the privacy statement.|
2317
2318**Error codes**
2319
2320For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
2321
2322| ID| Error Message|
2323| -------- | ---------------------------------------- |
2324|3301000 | Location service is unavailable.                                            |
2325
2326**Example**
2327
2328  ```ts
2329  import geoLocationManager from '@ohos.geoLocationManager';
2330  import BusinessError from "@ohos.base";
2331  try {
2332      geoLocationManager.setLocationPrivacyConfirmStatus(1, true);
2333  } catch (err) {
2334      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
2335  }
2336  ```
2337
2338
2339## geoLocationManager.getLocatingRequiredData<sup>10+</sup>
2340
2341getLocatingRequiredData(config: LocatingRequiredDataConfig): Promise&lt;Array&lt;LocatingRequiredData&gt;&gt;;
2342
2343Obtains the required data of the location service. This API uses a promise to return the result.
2344
2345**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
2346
2347**System capability**: SystemCapability.Location.Location.Core
2348
2349**System API**: This is a system API.
2350
2351**Parameters**
2352
2353  | Name| Type| Mandatory| Description|
2354  | -------- | -------- | -------- | -------- |
2355  | config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.|
2356
2357**Return value**
2358
2359  | Type| Description|
2360  | -------- | -------- |
2361  | [LocatingRequiredData](#locatingrequireddata10) | Promise used to receive the required data of the location service, such as the Wi-Fi and Bluetooth scanning information.|
2362
2363**Error codes**
2364
2365For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
2366
2367| ID| Error Message|
2368| -------- | ---------------------------------------- |
2369|3301800  | Failed to start WiFi or Bluetooth scanning.                    |
2370
2371**Example**
2372
2373  ```ts
2374  import geoLocationManager from '@ohos.geoLocationManager';
2375  import BusinessError from "@ohos.base";
2376  let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
2377  try {
2378      geoLocationManager.getLocatingRequiredData(config).then((result) => {
2379          console.log('getLocatingRequiredData return: ' + JSON.stringify(result));
2380      })
2381      .catch((error:number) => {
2382          console.error('promise, getLocatingRequiredData: error=' + JSON.stringify(error));
2383      });
2384  } catch (err) {
2385      console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
2386  }
2387  ```
2388