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