1# @ohos.geoLocationManager (Geolocation Manager) 2 3The **geoLocationManager** module provides basic location services such as Global Navigation Satellite System (GNSS)-based positioning, network positioning (for example, base station positioning or WLAN/Bluetooth positioning), geofencing, as well as geocoding and reverse geocoding. 4 5To use location services, turn on the Location switch on your device. If the switch is turned off while exception capture is disabled, the application may run into an error. 6 7> **NOTE** 8> 9> 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. 10> This module supports only the WGS-84 coordinate system. 11 12## Applying for Permissions 13 14For details, see [Applying for Location Permissions](../../device/location/location-guidelines.md#applying-for-location-permissions). 15 16 17## Modules to Import 18 19```ts 20import { geoLocationManager } from '@kit.LocationKit'; 21``` 22 23 24## ReverseGeoCodeRequest 25 26Defines a reverse geocoding request. 27 28**System capability**: SystemCapability.Location.Location.Geocoder 29 30| Name| Type| Read Only| Optional| Description| 31| -------- | -------- | -------- | -------- | -------- | 32| locale | string | No| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English. The default language is obtained from **Language and region** in **Settings**.| 33| country<sup>12+</sup> | string | No| Yes| Country information. The country code complies with the ISO 3166-1 alpha-2 standard. **CN** indicates China. The default language is obtained from **Language and region** in **Settings**.| 34| latitude | number | No| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**. Only the WGS84 coordinate system is supported.| 35| longitude | number | No| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**. Only the WGS84 coordinate system is supported.| 36| maxItems | number | No| 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. The default value is **1**.| 37 38 39## GeoCodeRequest 40 41Defines a reverse geocoding request. 42 43**System capability**: SystemCapability.Location.Location.Geocoder 44 45| Name| Type| Read Only| Optional| Description| 46| -------- | -------- | -------- | -------- | -------- | 47| locale | string | No| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English. The default language is obtained from **Language and region** in **Settings**.| 48| country<sup>12+</sup> | string | No| Yes| Country information. The country code complies with the ISO 3166-1 alpha-2 standard. **CN** indicates China. The default language is obtained from **Language and region** in **Settings**.| 49| description | string | No| No| Location description, for example, **No. xx, xx Road, Pudong New District, Shanghai**.| 50| maxItems | number | No| 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. The default value is **1**.| 51| minLatitude | number | No| 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**. Only the WGS84 coordinate system is supported. The following three parameters are mandatory is this parameter is specified.| 52| minLongitude | number | No| Yes| Minimum longitude. The value ranges from **-180** to **180**. Only the WGS84 coordinate system is supported.| 53| maxLatitude | number | No| Yes| Maximum latitude. The value ranges from **-90** to **90**. Only the WGS84 coordinate system is supported.| 54| maxLongitude | number | No| Yes| Maximum longitude. The value ranges from **-180** to **180**. Only the WGS84 coordinate system is supported.| 55 56 57## GeoAddress 58 59Geocoding address information. 60 61**System capability**: SystemCapability.Location.Location.Geocoder 62 63| Name| Type| Read Only| Optional| Description| 64| -------- | -------- | -------- | -------- | -------- | 65| latitude | number | No| Yes | Latitude information. A positive value indicates a north latitude, and a negative value indicates a south latitude. The value ranges from **-90** to **90**. Only the WGS84 coordinate system is supported.| 66| longitude | number | No| Yes | Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**. Only the WGS84 coordinate system is supported.| 67| locale | string | No| Yes | Language used for the location description. **zh** indicates Chinese, and **en** indicates English.| 68| placeName | string | No| Yes | Address information.| 69| countryCode | string | No| Yes | Country code.| 70| countryName | string | No| Yes| Country name.| 71| administrativeArea | string | No| Yes| Level-1 administrative region, which is generally is a province or state.| 72| subAdministrativeArea | string | No| Yes| Level-2 administrative region, which is generally is a city.| 73| locality | string | No| Yes| Locality information, which is usually a city.| 74| subLocality | string | No| Yes| Sub-locality information, which is usually a district or county.| 75| roadName | string | No| Yes| Road name.| 76| subRoadName | string | No| Yes| Auxiliary road information.| 77| premises | string | No| Yes| House information.| 78| postalCode | string | No| Yes| Postal code.| 79| phoneNumber | string | No| Yes| Phone number.| 80| addressUrl | string | No| Yes| Website URL.| 81| descriptions | Array<string> | No| Yes| Additional description. It contains **cityCode** (the array subscript is **0**) and **adminCode** (the array subscript is **1**), for example, **["025","320114001"]**.| 82| descriptionsSize | number | No| Yes| Total number of additional descriptions. The specified value must be greater than or equal to **0**. A value smaller than **10** is recommended.| 83 84 85## LocationRequest 86 87Defines a location request. 88 89**Atomic service API**: This API can be used in atomic services since API version 11. 90 91**System capability**: SystemCapability.Location.Location.Core 92 93| Name| Type| Read Only| Optional| Description| 94| -------- | -------- | -------- | -------- | -------- | 95| priority | [LocationRequestPriority](#locationrequestpriority) | No| 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).| 96| scenario | [LocationRequestScenario](#locationrequestscenario) | No| 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).| 97| timeInterval | number | No| Yes| Time interval at which location information is reported, in seconds.<br>The value is greater than or equal to 0.<br>The default value is the minimum interval allowed in the corresponding positioning mode.<br>The default value is 1s for GNSS positioning and 20s for network positioning.<br>If the value is less than the minimum interval, the minimum interval takes effect.<br>If the value is set to **0**, location information is directly reported without checking of the time interval.| 98| distanceInterval | number | No| 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**. If this parameter is set to **0**, there is no limitation on the location reporting distance.| 99| maxAccuracy | number | No| Yes| Location accuracy requested by the application, in meters. This parameter is valid only when the precise location function is enabled (both the **ohos.permission.APPROXIMATELY\_LOCATION** and **ohos.permission.LOCATION** permissions are granted). It is invalid when the approximate location function is enabled (only the **ohos.permission.APPROXIMATELY\_LOCATION** permission is enabled).<br>When this parameter is effective, the system compares the [location](#location) information reported by the GNSS or network location service with the location information requested by the application. If the accuracy in the reported [location](#location) information is less than or equal to **maxAccuracy**, the system sends the reported location information to the application. Otherwise, the system discards the location information.<br>The value must be greater than or equal to **0**. The default value is **0**, indicating no limitation on the location accuracy.<br>If **scenario** is set to **NAVIGATION**, **TRAJECTORY_TRACKING**, or **CAR_HAILING** or **priority** is set to **ACCURACY**, you are advised to set **maxAccuracy** to a value greater than **10**.<br>If scenario is set to **DAILY_LIFE_SERVICE** or **NO_POWER** or **priority** is set to **LOW_POWER** or **FIRST_FIX**, you are advised to set **maxAccuracy** to a value greater than **100**.<br>| 100 101 102## CurrentLocationRequest 103 104Defines a location request. 105 106**Atomic service API**: This API can be used in atomic services since API version 11. 107 108**System capability**: SystemCapability.Location.Location.Core 109 110| Name| Type| Read Only| Optional| Description| 111| -------- | -------- | -------- | -------- | -------- | 112| priority | [LocationRequestPriority](#locationrequestpriority) | No| 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).| 113| scenario | [LocationRequestScenario](#locationrequestscenario) | No| 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).| 114| maxAccuracy | number | No| Yes| Location accuracy requested by the application, in meters. This parameter is valid only when the precise location function is enabled (both the **ohos.permission.APPROXIMATELY\_LOCATION** and **ohos.permission.LOCATION** permissions are granted). It is invalid when the approximate location function is enabled (only the **ohos.permission.APPROXIMATELY\_LOCATION** permission is enabled).<br>When this parameter is effective, the system compares the [location](#location) information reported by the GNSS or network location service with the location information requested by the application. If the accuracy in the reported [location](#location) information is less than or equal to **maxAccuracy**, the system sends the reported location information to the application. Otherwise, the system discards the location information.<br>The value must be greater than or equal to **0**. The default value is **0**, indicating no limitation on the location accuracy.<br>If **scenario** is set to **NAVIGATION**, **TRAJECTORY_TRACKING**, or **CAR_HAILING** or **priority** is set to **ACCURACY**, you are advised to set **maxAccuracy** to a value greater than **10**.<br>If scenario is set to **DAILY_LIFE_SERVICE** or **NO_POWER** or **priority** is set to **LOW_POWER** or **FIRST_FIX**, you are advised to set **maxAccuracy** to a value greater than **100**.| 115| timeoutMs | number | No| Yes| Timeout duration, in milliseconds. The minimum value is **1000**. The specified value must be greater than or equal to **1000**.| 116 117 118## ContinuousLocationRequest<sup>12+</sup> 119 120Defines a continuous location request. 121 122**Atomic service API**: This API can be used in atomic services since API version 12. 123 124**System capability**: SystemCapability.Location.Location.Core 125 126| Name| Type| Read Only| Optional| Description| 127| -------- | -------- | -------- | -------- | -------- | 128| interval | number | No| No| 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**. If this parameter is set to **0**, there is no limitation on the location reporting interval.| 129| locationScenario | [UserActivityScenario](#useractivityscenario12) | [PowerConsumptionScenario](#powerconsumptionscenario12) | No| No| Location scenario. For details, see [UserActivityScenario](#useractivityscenario12) and [PowerConsumptionScenario](#powerconsumptionscenario12).| 130| sportsType<sup>18+</sup> | [SportsType](#sportstype18) | No| Yes| Sports type.<br>**Atomic service API**: This API can be used in atomic services since API version 18.| 131 132 133## SingleLocationRequest<sup>12+</sup> 134 135Defines a single location request. 136 137**Atomic service API**: This API can be used in atomic services since API version 12. 138 139**System capability**: SystemCapability.Location.Location.Core 140 141| Name| Type| Read Only| Optional| Description| 142| -------- | -------- | -------- | -------- | -------- | 143| locatingPriority | [LocatingPriority](#locatingpriority12) | No| No| Priority of the location request. For details, see [LocatingPriority](#locatingpriority12).| 144| locatingTimeoutMs | number | No| No| Timeout duration, in milliseconds. The minimum value is **1000**. The specified value must be greater than or equal to **1000**.| 145 146 147## SatelliteStatusInfo 148 149Defines the satellite status information. 150 151**System capability**: SystemCapability.Location.Location.Gnss 152 153| Name| Type| Read Only| Optional| Description| 154| -------- | -------- | -------- | -------- | -------- | 155| satellitesNumber | number | No| No| Number of satellites. The specified value must be greater than or equal to **0**.| 156| satelliteIds | Array<number> | No| No| Array of satellite IDs. The specified value must be greater than or equal to **0**.| 157| carrierToNoiseDensitys | Array<number> | No| No| Carrier-to-noise density ratio, that is, **cn0**. The specified value must be greater than **0**.| 158| altitudes | Array<number> | No| No| Satellite altitude angle information. The value ranges from **-90** to **90**, in degrees.| 159| azimuths | Array<number> | No| No| Azimuth information. The value ranges from **0** to **360**, in degrees.| 160| carrierFrequencies | Array<number> | No| No| Carrier frequency, in Hz. The specified value must be greater than or equal to **0**.| 161| satelliteConstellation<sup>12+</sup> | Array<[SatelliteConstellationCategory](#satelliteconstellationcategory12)> | No| Yes| Satellite constellation type.| 162| satelliteAdditionalInfo<sup>12+</sup> | Array<number> | No| Yes| Additional satellite information.<br>Each bit has a different meaning. For details, see [SatelliteAdditionalInfo](#satelliteadditionalinfo12).| 163 164 165## CachedGnssLocationsRequest 166 167Defines a request for reporting cached GNSS locations. 168 169**System capability**: SystemCapability.Location.Location.Gnss 170 171| Name| Type| Read Only| Optional| Description| 172| -------- | -------- | -------- | -------- | -------- | 173| reportingPeriodSec | number | No| No| Interval for reporting the cached GNSS locations, in milliseconds. The specified value must be greater than **0**.| 174| wakeUpCacheQueueFull | boolean | No| No | **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.| 175 176 177## Geofence 178 179Defines a GNSS geofence. Currently, only circular geofences are supported. 180 181**System capability**: SystemCapability.Location.Location.Geofence 182 183| Name| Type| Read Only| Optional| Description| 184| -------- | -------- | -------- | -------- | -------- | 185| latitude | number | No| No|Latitude information. The value ranges from **-90** to **90**.| 186| longitude | number | No|No| Longitude information. The value ranges from **-180** to **180**.| 187| coordinateSystemType<sup>12+</sup> | [CoordinateSystemType](#coordinatesystemtype12) | No|Yes| Coordinate system of the circle center of a geofence.<br>The application needs to call [getGeofenceSupportedCoordTypes](#geolocationmanagergetgeofencesupportedcoordtypes12) to query the supported coordinate systems and then pass in the correct coordinates of the circle center.| 188| radius | number | No|No| Radius of a circular geofence, in meters. The specified value must be greater than **0**.| 189| expiration | number | No|No| Expiration period of a geofence, in milliseconds. The specified value must be greater than **0**.| 190 191 192## GeofenceRequest 193 194Defines a geofence request. 195 196**System capability**: SystemCapability.Location.Location.Geofence 197 198| Name| Type| Read Only| Optional| Description| 199| -------- | -------- | -------- | -------- | -------- | 200| scenario | [LocationRequestScenario](#locationrequestscenario) | No| No | Location scenario.| 201| geofence | [Geofence](#geofence)| No| No | Geofence information.| 202 203 204## LocationCommand 205 206Defines a location command. 207 208**System capability**: SystemCapability.Location.Location.Core 209 210| Name| Type| Read Only| Optional| Description| 211| -------- | -------- | -------- | -------- | -------- | 212| scenario | [LocationRequestScenario](#locationrequestscenario) | No| No | Location scenario.| 213| command | string | No| No | Extended command, in the string format.| 214 215 216## Location 217 218Location information. 219 220**System capability**: SystemCapability.Location.Location.Core 221 222| Name| Type| Read Only| Optional| Description| 223| -------- | -------- | -------- | -------- | -------- | 224| latitude | number| No| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**. Only the WGS84 coordinate system is supported.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 225| longitude | number| No| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**. Only the WGS84 coordinate system is supported.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 226| altitude | number | No| No| Location altitude, in meters.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 227| accuracy | number | No| No| Location accuracy, in meters.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 228| speed | number | No| No|Speed, in m/s.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 229| timeStamp | number | No| No| Location timestamp in the UTC format.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 230| direction | number | No| No| Direction information. The value ranges from **0** to **360**, in degrees.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 231| timeSinceBoot | number | No| No| Timestamp when the location is successfully obtained. The value is the duration from the time when the device is booted to the time when the location is obtained, in nanoseconds.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 232| additions | Array<string>| No| Yes| Additional description.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 233| additionSize | number| No| Yes| Number of additional descriptions. The specified value must be greater than or equal to **0**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 234| additionsMap<sup>12+</sup> | Map<string, string>| No| Yes| Additional description. The content and sequence are the same as those of **additions**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 235| altitudeAccuracy<sup>12+</sup> |number | No| Yes| Height accuracy, in meters.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 236| speedAccuracy<sup>12+</sup> | number| No| Yes| Speed accuracy, in meters per second.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 237| directionAccuracy<sup>12+</sup> | number| No| Yes| Direction accuracy. The value ranges from **0** to **360**, in degrees.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 238| uncertaintyOfTimeSinceBoot<sup>12+</sup> | number| No| Yes| Uncertainty of the location timestamp.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 239| sourceType<sup>12+</sup> | [LocationSourceType](#locationsourcetype12) | No| Yes| Source of the location result.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 240 241 242## GeofenceTransition<sup>12+</sup> 243 244Defines a geofence transition event. 245 246**System capability**: SystemCapability.Location.Location.Geofence 247 248| Name| Type| Read Only| Optional| Description| 249| -------- | -------- | -------- | -------- | -------- | 250| geofenceId | number| No| No| Geofence ID.| 251| transitionEvent | [GeofenceTransitionEvent](#geofencetransitionevent12) | No| No| Geofence transition event.| 252 253 254## GnssGeofenceRequest<sup>12+</sup> 255 256Defines a GNSS geofence request. 257 258**System capability**: SystemCapability.Location.Location.Geofence 259 260| Name| Type| Read Only| Optional| Description| 261| -------- | -------- | -------- | -------- | -------- | 262| geofence | [Geofence](#geofence) | No| No| Geofence information, including the coordinates and radius of the circle center.| 263| monitorTransitionEvents | Array<[GeofenceTransitionEvent](#geofencetransitionevent12)> | No| No| List of geofence transition events.| 264| notifications | Array<[NotificationRequest](../apis-notification-kit/js-apis-notification.md#notificationrequest)> | No| Yes| List of notifications for geofence transition events.<br>The sequence of **monitorTransitionEvents** must correspond to that of **notifications**. For example, if **monitorTransitionEvents[0]** is **[GeofenceTransitionEvent](#geofencetransitionevent12).GEOFENCE_TRANSITION_EVENT_ENTER**, **notifications[0]** must be set to the notification that needs to be displayed when a user enters the geofence.| 265| geofenceTransitionCallback | AsyncCallback<[GeofenceTransition](#geofencetransition12)> | No| No| Callback used to receive geofence transition events.| 266 267 268## CountryCode 269 270Defines the country code information. 271 272**System capability**: SystemCapability.Location.Location.Core 273 274| Name| Type| Read Only| Optional| Description| 275| -------- | -------- | -------- | -------- | -------- | 276| country | string | No| No| Country code.| 277| type | [CountryCodeType](#countrycodetype) | No| No| Country code source.| 278 279 280## LocationRequestPriority 281 282Sets the priority of a location request. 283 284**Atomic service API**: This API can be used in atomic services since API version 11. 285 286**System capability**: SystemCapability.Location.Location.Core 287 288| Name| Value| Description| 289| -------- | -------- | -------- | 290| UNSET | 0x200 | Priority unspecified.<br>If this option is used, [LocationRequestPriority](#locationrequestpriority) is invalid.| 291| ACCURACY | 0x201 | Location accuracy.<br>The location accuracy priority mainly uses the GNSS positioning technology. The system uses the network positioning technology as an alternative to provide the location service for your application until the GNSS can provide stable location results. During the continuous location process, the network positioning technology is used if the GNSS location result cannot be obtained within 30 seconds. This policy can lead to significant hardware resource consumption and power consumption.| 292| LOW_POWER | 0x202 | Power efficiency.<br>This policy uses only the network positioning technology 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 if a high location accuracy is not required.| 293| 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 and network 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.| 294 295 296## LocationRequestScenario 297 298Defines the location scenario in a location request. 299 300**Atomic service API**: This API can be used in atomic services since API version 11. 301 302**System capability**: SystemCapability.Location.Location.Core 303 304> **NOTE** 305> 306> If a single location or continuous location is initiated in the NAVIGATION, TRAJECTORY_TRACKING, or CAR_HAILING scenario, the system uses the network positioning technology as an alternative to provide the location service for your application until the GNSS can provide stable location results. During the continuous location process, the network positioning technology is used if the GNSS location result cannot be obtained within 30 seconds. 307 308| Name| Value| Description| 309| -------- | -------- | -------- | 310| UNSET | 0x300 | Scenario unspecified.<br>If this option is used, [LocationRequestScenario](#locationrequestscenario) is invalid.| 311| 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>This option mainly uses the GNSS positioning technology and therefore the power consumption is relatively high.| 312| 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.<br>It mainly uses the GNSS positioning technology and therefore the power consumption is relatively high.| 313| 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>It mainly uses the GNSS positioning technology and therefore the power consumption is relatively high.| 314| DAILY_LIFE_SERVICE | 0x304 | Daily life services.<br>This option is applicable when your application only needs the approximate location in scenarios such as when the user is browsing news, shopping online, and ordering food.<br>It mainly uses the network positioning technology and therefore the power consumption is relatively low.| 315| 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.| 316 317 318## CountryCodeType 319 320Defines the country code source type. 321 322**System capability**: SystemCapability.Location.Location.Core 323 324| Name| Value| Description| 325| -------- | -------- | -------- | 326| COUNTRY_CODE_FROM_LOCALE | 1 | Country code obtained from the language configuration of the globalization module.| 327| COUNTRY_CODE_FROM_SIM | 2 | Country code obtained from the SIM card.| 328| COUNTRY_CODE_FROM_LOCATION | 3 | Country code obtained using the reverse geocoding function based on the user's location information.| 329| COUNTRY_CODE_FROM_NETWORK | 4 | Country code obtained from the cellular network registration information.| 330 331 332## CoordinateSystemType<sup>12+</sup> 333 334Enumerates coordinate system types. 335 336**System capability**: SystemCapability.Location.Location.Geofence 337 338| Name| Value| Description| 339| -------- | -------- | -------- | 340| WGS84 | 1 | World Geodetic System 1984, a coordinate system established for the use of the GPS.| 341| GCJ02 | 2 | GCJ-02, a coordinate system for the geographic information system developed by the State Bureau of Surveying and Mapping of China.| 342 343 344## GeofenceTransitionEvent<sup>12+</sup> 345 346Defines a geofence transition event. 347 348**System capability**: SystemCapability.Location.Location.Geofence 349 350| Name| Value| Description| 351| -------- | -------- | -------- | 352| GEOFENCE_TRANSITION_EVENT_ENTER | 1 | Event indicating that a device moves into a geofence.| 353| GEOFENCE_TRANSITION_EVENT_EXIT | 2 | Event indicating that a device moves out of a geofence.| 354| GEOFENCE_TRANSITION_EVENT_DWELL | 4 | Event indicating that a device stays in a geofence for more than 10s.| 355 356 357## SatelliteConstellationCategory<sup>12+</sup> 358 359Enumerates satellite constellation types. 360 361**System capability**: SystemCapability.Location.Location.Gnss 362 363| Name| Value| Description| 364| -------- | -------- | -------- | 365| CONSTELLATION_CATEGORY_UNKNOWN | 0 | Unknown type. This is the default value.| 366| CONSTELLATION_CATEGORY_GPS | 1 | Global positioning system (GPS), a high-precision radio navigation positioning system made up of artificial earth satellites launched by the United States.| 367| CONSTELLATION_CATEGORY_SBAS | 2 | Satellite-based augmentation system (SBAS), which supports wide-area or regional augmentation through the use of geostationary (GEO) satellites for broadcasting augmentation information, such as ephemeris error, satellite clock difference, and ionospheric delay, to users. It enhances the accuracy, integrity, and availability of basic global navigation satellite systems.| 368| CONSTELLATION_CATEGORY_GLONASS | 3 | Global navigation satellite system (GLONASS), a Russia space-based satellite navigation system that provides a global coverage positioning service similar to the GPS.| 369| CONSTELLATION_CATEGORY_QZSS | 4 | Quasi-Zenith satellite system (QZSS), a regional navigation satellite system developed by Japan to enhance and augment GPS coverage over Japan's territory.| 370| CONSTELLATION_CATEGORY_BEIDOU | 5 | Beidou navigation satellite system (BNSS), a global satellite navigation system developed by China.| 371| CONSTELLATION_CATEGORY_GALILEO | 6 | Galileo satellite navigation system (GALILEO), a global satellite navigation and positioning system developed and established by the European Union.| 372| CONSTELLATION_CATEGORY_IRNSS | 7 | Indian regional navigation satellite system (IRNSS), an independent regional satellite navigation system developed and operated by India.| 373 374 375## SatelliteAdditionalInfo<sup>12+</sup> 376 377Enumerates the types of additional satellite information. 378 379**System capability**: SystemCapability.Location.Location.Gnss 380 381| Name| Value| Description| 382| -------- | -------- | -------- | 383| SATELLITES_ADDITIONAL_INFO_NULL | 0 | No additional information. This is the default value.| 384| SATELLITES_ADDITIONAL_INFO_EPHEMERIS_DATA_EXIST | 1 | Ephemeris data.| 385| SATELLITES_ADDITIONAL_INFO_ALMANAC_DATA_EXIST | 2 | Almanac data.| 386| SATELLITES_ADDITIONAL_INFO_USED_IN_FIX | 4 | Use of the satellite in the latest location resolution.| 387| SATELLITES_ADDITIONAL_INFO_CARRIER_FREQUENCY_EXIST | 8 | Presence of carrier frequencies on the satellite.| 388 389 390## PowerConsumptionScenario<sup>12+</sup> 391 392Enumerates power consumption scenarios in a location request. 393 394**Atomic service API**: This API can be used in atomic services since API version 12. 395 396**System capability**: SystemCapability.Location.Location.Core 397 398| Name| Value| Description| 399| -------- | -------- | -------- | 400| HIGH_POWER_CONSUMPTION | 0x601 | High power consumption.<br>The mode mainly uses the GNSS positioning technology. The system uses the network positioning technology as an alternative to provide the location service for your application until the GNSS can provide stable location results. During the continuous location process, the network positioning technology is used if the GNSS location result cannot be obtained within 30 seconds. This policy can lead to significant hardware resource consumption and power consumption.| 401| LOW_POWER_CONSUMPTION | 0x602 | Low power consumption.<br>This mode is applicable when your application only needs the approximate location in scenarios such as when the user is browsing news, shopping online, and ordering food.<br>It mainly uses the network positioning technology and therefore the power consumption is relatively low.| 402| NO_POWER_CONSUMPTION | 0x603 | No power consumption.<br>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. | 403 404 405## UserActivityScenario<sup>12+</sup> 406 407Enumerates user activity scenarios in a location request. 408 409**Atomic service API**: This API can be used in atomic services since API version 12. 410 411**System capability**: SystemCapability.Location.Location.Core 412 413> **NOTE** 414> 415> If a single location or continuous location is initiated in the NAVIGATION, SPORT, or TRANSPORT scenario, the system uses the network positioning technology as an alternative to provide the location service for your application until the GNSS can provide stable location results. During the continuous location process, the network positioning technology is used if the GNSS location result cannot be obtained within 30 seconds. 416 417| Name| Value| Description| 418| -------- | -------- | -------- | 419| NAVIGATION | 0x401 | 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>It mainly uses the GNSS positioning technology and therefore the power consumption is relatively high.| 420| SPORT | 0x402 | Sport scenario.<br>This option is applicable when your application needs to record user trajectories, for example, the track recording function of sports applications.<br>It mainly uses the GNSS positioning technology and therefore the power consumption is relatively high.| 421| TRANSPORT | 0x403 | Travel scenario.<br>This option is applicable to user travel scenarios, such as taxi hailing and public transportation.<br>This option mainly uses the GNSS positioning technology and therefore the power consumption is relatively high. | 422| DAILY_LIFE_SERVICE | 0x404 | Daily life service scenario.<br>This option is applicable when your application only needs the approximate location in scenarios such as when the user is browsing news, shopping online, and ordering food.<br>It mainly uses the network positioning technology and therefore the power consumption is relatively low. | 423 424 425## LocatingPriority<sup>12+</sup> 426 427Enumerates priority types in a single location request. 428 429**Atomic service API**: This API can be used in atomic services since API version 12. 430 431**System capability**: SystemCapability.Location.Location.Core 432 433| Name| Value| Description| 434| -------- | -------- | -------- | 435| PRIORITY_ACCURACY | 0x501 | Location accuracy.<br>This policy uses both the GNSS positioning and network positioning technologies and provides the most accurate location result within the specified period of time, which is the smaller one between [SingleLocationRequest](#singlelocationrequest12).locatingTimeoutMs and 30 seconds.<br>This policy can lead to significant hardware resource consumption and power consumption. | 436| PRIORITY_LOCATING_SPEED | 0x502 | Fast location preferred. Use this policy if you want to obtain a location as fast as possible.<br>This policy uses the GNSS positioning and network positioning technologies simultaneously to obtain the device location in both the indoor and outdoor scenarios and provides the first obtained location result to your application. This policy can lead to significant hardware resource consumption and power consumption.| 437 438 439## LocationError<sup>12+</sup> 440 441Enumerates error codes in a continuous location request. 442 443**Atomic service API**: This API can be used in atomic services since API version 12. 444 445**System capability**: SystemCapability.Location.Location.Core 446 447| Name| Value| Description| 448| -------- | -------- | -------- | 449| LOCATING_FAILED_DEFAULT | -1 | Unknown type. This is the default value.| 450| LOCATING_FAILED_LOCATION_PERMISSION_DENIED | -2 | Failed to verify the **ohos.permission.APPROXIMATELY_LOCATION** or **ohos.permission.LOCATION** permission.| 451| LOCATING_FAILED_BACKGROUND_PERMISSION_DENIED | -3 | Failed to verify the location permission when the application is running in the background. For details about how to apply for the location permission, see [Applying for Location Permissions](../../device/location/location-guidelines.md#applying-for-location-permissions).| 452| LOCATING_FAILED_LOCATION_SWITCH_OFF | -4 | Location switch turned off.| 453| LOCATING_FAILED_INTERNET_ACCESS_FAILURE | -5 | Network access denied.| 454 455 456## LocationSourceType<sup>12+</sup> 457 458Defines the source of the location result. 459 460**Atomic service API**: This API can be used in atomic services since API version 12. 461 462**System capability**: SystemCapability.Location.Location.Core 463 464| Name| Value| Description| 465| -------- | -------- | -------- | 466| GNSS | 1 | GNSS positioning technology.| 467| NETWORK | 2 | Network positioning technology.| 468| INDOOR | 3 | Indoor high-precision positioning technology.| 469| RTK | 4 | Outdoor high-precision positioning technology.| 470 471 472## BluetoothScanResult<sup>16+</sup> 473 474Defines the Bluetooth scan result. 475 476**System capability**: SystemCapability.Location.Location.Core 477 478| Name| Type| Read Only| Optional| Description| 479| -------- | -------- | -------- | -------- | -------- | 480| deviceId | string | Yes| No| Address of the device discovered, for example, XX:XX:XX:XX:XX:XX.| 481| rssi | number | Yes| No| RSSI of the device.| 482| data | ArrayBuffer | Yes| Yes| Advertising packets sent by the device.| 483| deviceName | string | Yes| No| Name of the device detected.| 484| connectable | boolean | Yes| No| Whether the discovered device is connectable. The value **true** means the discovered device is connectable, and the value **false** means the opposite.| 485 486 487## SportsType<sup>18+</sup> 488 489Enumerates sports types. 490 491**Atomic service API**: This API can be used in atomic services since API version 18. 492 493**System capability**: SystemCapability.Location.Location.Core 494 495| Name| Value| Description| 496| -------- | -------- | -------- | 497| RUNNING | 1 | Running.| 498| WALKING | 2 | Walking.| 499| CYCLING | 3 | Cycling.| 500 501 502## geoLocationManager.on('locationChange') 503 504on(type: 'locationChange', request: LocationRequest | ContinuousLocationRequest, callback: Callback<Location>): void 505 506Subscribes to location change events with a location request initiated. This API uses an asynchronous callback to return the result. 507 508**Atomic service API**: This API can be used in atomic services since API version 11. 509 510**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 511 512**System capability**: SystemCapability.Location.Location.Core 513 514**Parameters** 515 516 | Name| Type| Mandatory| Description| 517 | -------- | -------- | -------- | -------- | 518 | type | string | Yes| Event type. The value **locationChange** indicates a location change.| 519 | request | [LocationRequest](#locationrequest) | [ContinuousLocationRequest](#continuouslocationrequest12) | Yes| Location request.<br>**ContinuousLocationRequest** is newly added in API version 12.| 520 | callback | Callback<[Location](#location)> | Yes| Callback used to return the result.| 521 522**Error codes** 523 524For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 525 526| ID| Error Message| 527| -------- | ---------------------------------------- | 528|201 | Permission verification failed. The application does not have the permission required to call the API. | 529|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 530|801 | Capability not supported. Failed to call ${geoLocationManager.on('locationChange')} due to limited device capabilities. | 531|3301000 | The location service is unavailable. | 532|3301100 | The location switch is off. | 533 534**Example** 535 536 ```ts 537 import { geoLocationManager } from '@kit.LocationKit'; 538 539 // Method 1: Use LocationRequest as the input parameter. 540 let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0}; 541 let locationChange = (location:geoLocationManager.Location):void => { 542 console.info('locationChanger: data: ' + JSON.stringify(location)); 543 }; 544 try { 545 geoLocationManager.on('locationChange', requestInfo, locationChange); 546 } catch (err) { 547 console.error("errCode:" + err.code + ", message:" + err.message); 548 } 549 550 // Method 2: Use ContinuousLocationRequest as the input parameter. 551 let request:geoLocationManager.ContinuousLocationRequest = {'interval': 1, 'locationScenario': geoLocationManager.UserActivityScenario.NAVIGATION}; 552 let locationCallback = (location:geoLocationManager.Location):void => { 553 console.info('locationCallback: data: ' + JSON.stringify(location)); 554 }; 555 try { 556 geoLocationManager.on('locationChange', request, locationCallback); 557 } catch (err) { 558 console.error("errCode:" + err.code + ", message:" + err.message); 559 } 560 ``` 561 562 563## geoLocationManager.off('locationChange') 564 565off(type: 'locationChange', callback?: Callback<Location>): void 566 567Unregisters the listener for location change events with the corresponding location request deleted. 568 569**Atomic service API**: This API can be used in atomic services since API version 11. 570 571**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 572 573**System capability**: SystemCapability.Location.Location.Core 574 575**Parameters** 576 577 | Name| Type| Mandatory| Description| 578 | -------- | -------- | -------- | -------- | 579 | type | string | Yes| Event type. The value **locationChange** indicates a location change.| 580 | callback | Callback<[Location](#location)> | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 581 582**Error codes** 583 584For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 585 586| ID| Error Message| 587| -------- | ---------------------------------------- | 588|201 | Permission verification failed. The application does not have the permission required to call the API. | 589|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 590|801 | Capability not supported. Failed to call ${geoLocationManager.off('locationChange')} due to limited device capabilities. | 591|3301000 | The location service is unavailable. | 592 593**Example** 594 595 ```ts 596 import { geoLocationManager } from '@kit.LocationKit'; 597 598 let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0}; 599 let locationChange = (location:geoLocationManager.Location):void => { 600 console.info('locationChanger: data: ' + JSON.stringify(location)); 601 }; 602 try { 603 geoLocationManager.on('locationChange', requestInfo, locationChange); 604 geoLocationManager.off('locationChange', locationChange); 605 } catch (err) { 606 console.error("errCode:" + err.code + ", message:" + err.message); 607 } 608 ``` 609 610 611## geoLocationManager.on('locationError')<sup>12+</sup> 612 613on(type: 'locationError', callback: Callback<LocationError>): void 614 615Registers a listener for error codes generated during continuous location. This API uses an asynchronous callback to return the result. 616 617**Atomic service API**: This API can be used in atomic services since API version 12. 618 619**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 620 621**System capability**: SystemCapability.Location.Location.Core 622 623**Parameters** 624 625 | Name| Type| Mandatory| Description| 626 | -------- | -------- | -------- | -------- | 627 | type | string | Yes| Event type. To subscribe to error codes generated during continuous location, set the value to **locationError**.| 628 | callback | Callback<[LocationError](#locationerror12)> | Yes| Callback used to return the result.| 629 630**Error codes** 631 632For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 633 634| ID| Error Message| 635| -------- | ---------------------------------------- | 636|201 | Permission verification failed. The application does not have the permission required to call the API. | 637|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 638|801 | Capability not supported. Failed to call ${geoLocationManager.on('locationError')} due to limited device capabilities. | 639|3301000 | The location service is unavailable. | 640 641**Example** 642 643 ```ts 644 import { geoLocationManager } from '@kit.LocationKit'; 645 646 let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0}; 647 let locationChange = (location:geoLocationManager.Location):void => { 648 console.info('locationChanger: data: ' + JSON.stringify(location)); 649 }; 650 try { 651 geoLocationManager.on('locationChange', requestInfo, locationChange); 652 } catch (err) { 653 console.error("errCode:" + err.code + ", message:" + err.message); 654 } 655 656 let locationErrorChange = (errcode: geoLocationManager.LocationError):void => { 657 console.info('locationErrorChange: data: ' + JSON.stringify(errcode)); 658 }; 659 try { 660 geoLocationManager.on('locationError', locationErrorChange); 661 } catch (err) { 662 console.error("errCode:" + err.code + ", message:" + err.message); 663 } 664 665 ``` 666 667 668## geoLocationManager.off('locationError')<sup>12+</sup> 669 670off(type: 'locationError', callback?: Callback<LocationError>): void 671 672Unregisters the listener for error codes generated during continuous location. 673 674**Atomic service API**: This API can be used in atomic services since API version 12. 675 676**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 677 678**System capability**: SystemCapability.Location.Location.Core 679 680**Parameters** 681 682 | Name| Type| Mandatory| Description| 683 | -------- | -------- | -------- | -------- | 684 | type | string | Yes| Event type. To subscribe to error codes generated during continuous location, set the value to **locationError**.| 685 | callback | Callback<[LocationError](#locationerror12)> | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 686 687**Error codes** 688 689For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 690 691| ID| Error Message| 692| -------- | ---------------------------------------- | 693|201 | Permission verification failed. The application does not have the permission required to call the API. | 694|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 695|801 | Capability not supported. Failed to call ${geoLocationManager.off('locationError')} due to limited device capabilities. | 696|3301000 | The location service is unavailable. | 697 698**Example** 699 700 ```ts 701 import { geoLocationManager } from '@kit.LocationKit'; 702 703 let locationErrorChange = (errcode: geoLocationManager.LocationError):void => { 704 console.info('locationErrorChange: data: ' + JSON.stringify(errcode)); 705 }; 706 try { 707 geoLocationManager.on('locationError', locationErrorChange); 708 geoLocationManager.off('locationError', locationErrorChange); 709 } catch (err) { 710 console.error("errCode:" + err.code + ", message:" + err.message); 711 } 712 ``` 713 714 715## geoLocationManager.on('locationEnabledChange') 716 717on(type: 'locationEnabledChange', callback: Callback<boolean>): void 718 719Subscribes to location service status change events. This API uses an asynchronous callback to return the result. 720 721**System capability**: SystemCapability.Location.Location.Core 722 723**Parameters** 724 725 | Name| Type| Mandatory| Description| 726 | -------- | -------- | -------- | -------- | 727 | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change.| 728 | callback | Callback<boolean> | Yes| Callback used to return the result. The value **true** indicates that the location switch is enabled and the value **false** indicates the opposite.| 729 730**Error codes** 731 732For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 733 734| ID| Error Message| 735| -------- | ---------------------------------------- | 736|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 737|801 | Capability not supported. Failed to call ${geoLocationManager.on('locationEnabledChange')} due to limited device capabilities. | 738|3301000 | The location service is unavailable. | 739 740**Example** 741 742 ```ts 743 import { geoLocationManager } from '@kit.LocationKit'; 744 745 let locationEnabledChange = (state:boolean):void => { 746 console.info('locationEnabledChange: ' + JSON.stringify(state)); 747 } 748 try { 749 geoLocationManager.on('locationEnabledChange', locationEnabledChange); 750 } catch (err) { 751 console.error("errCode:" + err.code + ", message:" + err.message); 752 } 753 ``` 754 755 756## geoLocationManager.off('locationEnabledChange') 757 758off(type: 'locationEnabledChange', callback?: Callback<boolean>): void 759 760Unsubscribes from location service status change events. 761 762**System capability**: SystemCapability.Location.Location.Core 763 764**Parameters** 765 766 | Name| Type| Mandatory| Description| 767 | -------- | -------- | -------- | -------- | 768 | type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change.| 769 | callback | Callback<boolean> | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 770 771**Error codes** 772 773For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 774 775| ID| Error Message| 776| -------- | ---------------------------------------- | 777|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 778|801 | Capability not supported. Failed to call ${geoLocationManager.off('locationEnabledChange')} due to limited device capabilities. | 779|3301000 | The location service is unavailable. | 780 781**Example** 782 783 ```ts 784 import { geoLocationManager } from '@kit.LocationKit'; 785 786 let locationEnabledChange = (state:boolean):void => { 787 console.info('locationEnabledChange: state: ' + JSON.stringify(state)); 788 } 789 try { 790 geoLocationManager.on('locationEnabledChange', locationEnabledChange); 791 geoLocationManager.off('locationEnabledChange', locationEnabledChange); 792 } catch (err) { 793 console.error("errCode:" + err.code + ", message:" + err.message); 794 } 795 ``` 796 797 798## geoLocationManager.on('cachedGnssLocationsChange') 799 800on(type: 'cachedGnssLocationsChange', request: CachedGnssLocationsRequest, callback: Callback<Array<Location>>): void 801 802Subscribes 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. This API uses an asynchronous callback to return the result. 803 804**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 805 806**System capability**: SystemCapability.Location.Location.Gnss 807 808**Parameters** 809 810 | Name| Type| Mandatory| Description| 811 | -------- | -------- | -------- | -------- | 812 | type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.| 813 | request | [CachedGnssLocationsRequest](#cachedgnsslocationsrequest) | Yes| Request for reporting cached GNSS location.| 814 | callback | Callback<Array<[Location](#location)>> | Yes| Callback used to return the result.| 815 816**Error codes** 817 818For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 819 820| ID| Error Message| 821| -------- | ---------------------------------------- | 822|201 | Permission verification failed. The application does not have the permission required to call the API. | 823|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 824|801 | Capability not supported. Failed to call ${geoLocationManager.on('cachedGnssLocationsChange')} due to limited device capabilities. | 825|3301000 | The location service is unavailable. | 826|3301100 | The location switch is off. | 827 828**Example** 829 830 ```ts 831 import { geoLocationManager } from '@kit.LocationKit'; 832 833 let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => { 834 console.info('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations)); 835 } 836 let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; 837 try { 838 geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb); 839 } catch (err) { 840 console.error("errCode:" + err.code + ", message:" + err.message); 841 } 842 ``` 843 844 845## geoLocationManager.off('cachedGnssLocationsChange') 846 847off(type: 'cachedGnssLocationsChange', callback?: Callback<Array<Location>>): void 848 849Unsubscribes 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. 850 851**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 852 853**System capability**: SystemCapability.Location.Location.Gnss 854 855**Parameters** 856 857 | Name| Type| Mandatory| Description| 858 | -------- | -------- | -------- | -------- | 859 | type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.| 860 | callback | Callback<Array<[Location](#location)>> | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 861 862**Error codes** 863 864For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 865 866| ID| Error Message| 867| -------- | ---------------------------------------- | 868|201 | Permission verification failed. The application does not have the permission required to call the API. | 869|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 870|801 | Capability not supported. Failed to call ${geoLocationManager.off('cachedGnssLocationsChange')} due to limited device capabilities. | 871|3301000 | The location service is unavailable. | 872|3301100 | The location switch is off. | 873 874**Example** 875 876 ```ts 877 import { geoLocationManager } from '@kit.LocationKit'; 878 879 let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => { 880 console.info('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations)); 881 } 882 let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; 883 try { 884 geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb); 885 geoLocationManager.off('cachedGnssLocationsChange'); 886 } catch (err) { 887 console.error("errCode:" + err.code + ", message:" + err.message); 888 } 889 ``` 890 891 892## geoLocationManager.on('satelliteStatusChange') 893 894on(type: 'satelliteStatusChange', callback: Callback<SatelliteStatusInfo>): void 895 896Subscribes to GNSS satellite status change events. This API uses an asynchronous callback to return the result. 897 898**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 899 900**System capability**: SystemCapability.Location.Location.Gnss 901 902**Parameters** 903 904 | Name| Type| Mandatory| Description| 905 | -------- | -------- | -------- | -------- | 906 | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change.| 907 | callback | Callback<[SatelliteStatusInfo](#satellitestatusinfo)> | Yes| Callback used to return the result.| 908 909**Error codes** 910 911For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 912 913| ID| Error Message| 914| -------- | ---------------------------------------- | 915|201 | Permission verification failed. The application does not have the permission required to call the API. | 916|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 917|801 | Capability not supported. Failed to call ${geoLocationManager.on('satelliteStatusChange')} due to limited device capabilities. | 918|3301000 | The location service is unavailable. | 919|3301100 | The location switch is off. | 920 921**Example** 922 923 ```ts 924 import { geoLocationManager } from '@kit.LocationKit'; 925 926 let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => { 927 console.info('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo)); 928 // Number of satellites. 929 let totalNumber: number = satelliteStatusInfo.satellitesNumber; 930 let satelliteIds: Array<number> = satelliteStatusInfo.satelliteIds; 931 let carrierToNoiseDensitys: Array<number> = satelliteStatusInfo.carrierToNoiseDensitys; 932 let altitudes: Array<number> = satelliteStatusInfo.altitudes; 933 let azimuths: Array<number> = satelliteStatusInfo.azimuths; 934 let carrierFrequencies: Array<number> = satelliteStatusInfo.carrierFrequencies; 935 let satelliteConstellations: Array<geoLocationManager.SatelliteConstellationCategory> | undefined = satelliteStatusInfo.satelliteConstellation; 936 let satelliteAdditionalInfos: Array<number> | undefined = satelliteStatusInfo.satelliteAdditionalInfo; 937 for (let i = 0;i < totalNumber;i++) { 938 // Satellite ID. 939 let satelliteId: Number = satelliteIds[i]; 940 // Carrier-to-noise density ratio of the satellite whose ID is ${satelliteId}. 941 let carrierToNoiseDensity: Number = carrierToNoiseDensitys[i]; 942 // Altitude angle information of the satellite whose ID is ${satelliteId}. 943 let altitude: Number = altitudes[i]; 944 // Azimuth of the satellite whose ID is ${satelliteId}. 945 let azimuth: Number = azimuths[i]; 946 // Carrier frequency of the satellite whose ID is ${satelliteId}. 947 let carrierFrequencie: Number = carrierFrequencies[i]; 948 if (satelliteConstellations != undefined) { 949 // Constellation of the satellite whose ID is ${satelliteId}. 950 let satelliteConstellation: geoLocationManager.SatelliteConstellationCategory = satelliteConstellations[i]; 951 } 952 if (satelliteAdditionalInfos != undefined) { 953 // Additional information about the satellite whose ID is ${satelliteId}, for example, use of the satellite in the latest location resolution and the availability of ephemeris data, almanac data, and carrier frequency information. 954 let satelliteAdditionalInfo: Number = satelliteAdditionalInfos[i]; 955 } 956 } 957 } 958 959 try { 960 geoLocationManager.on('satelliteStatusChange', gnssStatusCb); 961 } catch (err) { 962 console.error("errCode:" + err.code + ", message:" + err.message); 963 } 964 ``` 965 966 967## geoLocationManager.off('satelliteStatusChange') 968 969off(type: 'satelliteStatusChange', callback?: Callback<SatelliteStatusInfo>): void 970 971Unsubscribes from GNSS satellite status change events. 972 973**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 974 975**System capability**: SystemCapability.Location.Location.Gnss 976 977**Parameters** 978 979 | Name| Type| Mandatory| Description| 980 | -------- | -------- | -------- | -------- | 981 | type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change.| 982 | callback | Callback<[SatelliteStatusInfo](#satellitestatusinfo)> | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 983 984**Error codes** 985 986For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 987 988| ID| Error Message| 989| -------- | ---------------------------------------- | 990|201 | Permission verification failed. The application does not have the permission required to call the API. | 991|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 992|801 | Capability not supported. Failed to call ${geoLocationManager.off('satelliteStatusChange')} due to limited device capabilities. | 993|3301000 | The location service is unavailable. | 994|3301100 | The location switch is off. | 995 996 997**Example** 998 999 ```ts 1000 import { geoLocationManager } from '@kit.LocationKit'; 1001 1002 let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => { 1003 console.info('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo)); 1004 } 1005 try { 1006 geoLocationManager.on('satelliteStatusChange', gnssStatusCb); 1007 geoLocationManager.off('satelliteStatusChange', gnssStatusCb); 1008 } catch (err) { 1009 console.error("errCode:" + err.code + ", message:" + err.message); 1010 } 1011 ``` 1012 1013 1014## geoLocationManager.on('nmeaMessage') 1015 1016on(type: 'nmeaMessage', callback: Callback<string>): void 1017 1018Subscribes to GNSS NMEA message change events. This API uses an asynchronous callback to return the result. 1019 1020**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 1021 1022**System capability**: SystemCapability.Location.Location.Gnss 1023 1024**Parameters** 1025 1026 | Name| Type| Mandatory| Description| 1027 | -------- | -------- | -------- | -------- | 1028 | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change.| 1029 | callback | Callback<string> | Yes| Callback used to return the result.| 1030 1031**Error codes** 1032 1033For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1034 1035| ID| Error Message| 1036| -------- | ---------------------------------------- | 1037|201 | Permission verification failed. The application does not have the permission required to call the API. | 1038|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1039|801 | Capability not supported. Failed to call ${geoLocationManager.on('nmeaMessage')} due to limited device capabilities. | 1040|3301000 | The location service is unavailable. | 1041|3301100 | The location switch is off. | 1042 1043 1044**Example** 1045 1046 ```ts 1047 import { geoLocationManager } from '@kit.LocationKit'; 1048 1049 let nmeaCb = (str:string):void => { 1050 console.info('nmeaMessage: ' + JSON.stringify(str)); 1051 } 1052 1053 try { 1054 geoLocationManager.on('nmeaMessage', nmeaCb ); 1055 } catch (err) { 1056 console.error("errCode:" + err.code + ", message:" + err.message); 1057 } 1058 ``` 1059 1060 1061## geoLocationManager.off('nmeaMessage') 1062 1063off(type: 'nmeaMessage', callback?: Callback<string>): void 1064 1065Unsubscribes from GNSS NMEA message change events. 1066 1067**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 1068 1069**System capability**: SystemCapability.Location.Location.Gnss 1070 1071**Parameters** 1072 1073 | Name| Type| Mandatory| Description| 1074 | -------- | -------- | -------- | -------- | 1075 | type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change.| 1076 | callback | Callback<string> | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 1077 1078**Error codes** 1079 1080For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1081 1082| ID| Error Message| 1083| -------- | ---------------------------------------- | 1084|201 | Permission verification failed. The application does not have the permission required to call the API. | 1085|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1086|801 | Capability not supported. Failed to call ${geoLocationManager.off('nmeaMessage')} due to limited device capabilities. | 1087|3301000 | The location service is unavailable. | 1088|3301100 | The location switch is off. | 1089 1090 1091**Example** 1092 1093 ```ts 1094 import { geoLocationManager } from '@kit.LocationKit'; 1095 1096 let nmeaCb = (str:string):void => { 1097 console.info('nmeaMessage: ' + JSON.stringify(str)); 1098 } 1099 1100 try { 1101 geoLocationManager.on('nmeaMessage', nmeaCb); 1102 geoLocationManager.off('nmeaMessage', nmeaCb); 1103 } catch (err) { 1104 console.error("errCode:" + err.code + ", message:" + err.message); 1105 } 1106 ``` 1107 1108 1109## geoLocationManager.on('gnssFenceStatusChange') 1110 1111on(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void 1112 1113Subscribes 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. 1114 1115**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1116 1117**System capability**: SystemCapability.Location.Location.Geofence 1118 1119**Parameters** 1120 1121 | Name| Type| Mandatory| Description| 1122 | -------- | -------- | -------- | -------- | 1123 | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.| 1124 | request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.| 1125 | want | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.| 1126 1127**Error codes** 1128 1129For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1130 1131| ID| Error Message| 1132| -------- | ---------------------------------------- | 1133|201 | Permission verification failed. The application does not have the permission required to call the API. | 1134|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1135|801 | Capability not supported. Failed to call ${geoLocationManager.on('gnssFenceStatusChange')} due to limited device capabilities. | 1136|3301000 | The location service is unavailable. | 1137|3301100 | The location switch is off. | 1138|3301600 | Failed to operate the geofence. | 1139 1140**Example** 1141 1142 ```ts 1143 import { geoLocationManager } from '@kit.LocationKit'; 1144 import { wantAgent } from '@kit.AbilityKit'; 1145 1146 1147 let wantAgentInfo:wantAgent.WantAgentInfo = { 1148 wants: [ 1149 { 1150 bundleName: "com.example.myapplication", 1151 abilityName: "EntryAbility", 1152 action: "action1" 1153 } 1154 ], 1155 operationType: wantAgent.OperationType.START_ABILITY, 1156 requestCode: 0, 1157 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 1158 }; 1159 1160 wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { 1161 let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 31.12, "longitude": 121.11, "radius": 100, "expiration": 10000}}; 1162 try { 1163 geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj); 1164 } catch (err) { 1165 console.error("errCode:" + err.code + ", message:" + err.message); 1166 } 1167 }); 1168 ``` 1169 1170 1171## geoLocationManager.off('gnssFenceStatusChange') 1172 1173off(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void 1174 1175Unsubscribes 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. 1176 1177**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1178 1179**System capability**: SystemCapability.Location.Location.Geofence 1180 1181**Parameters** 1182 1183 | Name| Type| Mandatory| Description| 1184 | -------- | -------- | -------- | -------- | 1185 | type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.| 1186 | request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.| 1187 | want | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.| 1188 1189**Error codes** 1190 1191For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1192 1193| ID| Error Message| 1194| -------- | ---------------------------------------- | 1195|201 | Permission verification failed. The application does not have the permission required to call the API. | 1196|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1197|801 | Capability not supported. Failed to call ${geoLocationManager.off('gnssFenceStatusChange')} due to limited device capabilities. | 1198|3301000 | The location service is unavailable. | 1199|3301100 | The location switch is off. | 1200|3301600 | Failed to operate the geofence. | 1201 1202**Example** 1203 1204 ```ts 1205 import { geoLocationManager } from '@kit.LocationKit'; 1206 import { wantAgent } from '@kit.AbilityKit'; 1207 1208 1209 let wantAgentInfo:wantAgent.WantAgentInfo = { 1210 wants: [ 1211 { 1212 bundleName: "com.example.myapplication", 1213 abilityName: "EntryAbility", 1214 action: "action1", 1215 } 1216 ], 1217 operationType: wantAgent.OperationType.START_ABILITY, 1218 requestCode: 0, 1219 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 1220 }; 1221 1222 wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { 1223 let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 31.12, "longitude": 121.11, "radius": 100, "expiration": 10000}};; 1224 try { 1225 geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj); 1226 geoLocationManager.off('gnssFenceStatusChange', requestInfo, wantAgentObj); 1227 } catch (err) { 1228 console.error("errCode:" + err.code + ", message:" + err.message); 1229 } 1230 }); 1231 ``` 1232 1233 1234## geoLocationManager.on('countryCodeChange') 1235 1236on(type: 'countryCodeChange', callback: Callback<CountryCode>): void 1237 1238Subscribes to country code change events. This API uses an asynchronous callback to return the result. 1239 1240**System capability**: SystemCapability.Location.Location.Core 1241 1242**Parameters** 1243 1244 | Name| Type| Mandatory| Description| 1245 | -------- | -------- | -------- | -------- | 1246 | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change.| 1247 | callback | Callback<[CountryCode](#countrycode)> | Yes| Callback used to return the result.| 1248 1249**Error codes** 1250 1251For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1252 1253| ID| Error Message| 1254| -------- | ---------------------------------------- | 1255|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1256|801 | Capability not supported. Failed to call ${geoLocationManager.on('countryCodeChange')} due to limited device capabilities. | 1257|3301000 | The location service is unavailable. | 1258|3301500 | Failed to query the area information. | 1259 1260 1261**Example** 1262 1263 ```ts 1264 import { geoLocationManager } from '@kit.LocationKit'; 1265 1266 let callback = (code:geoLocationManager.CountryCode):void => { 1267 console.info('countryCodeChange: ' + JSON.stringify(code)); 1268 } 1269 1270 try { 1271 geoLocationManager.on('countryCodeChange', callback); 1272 } catch (err) { 1273 console.error("errCode:" + err.code + ", message:" + err.message); 1274 } 1275 ``` 1276 1277 1278## geoLocationManager.off('countryCodeChange') 1279 1280off(type: 'countryCodeChange', callback?: Callback<CountryCode>): void 1281 1282Unsubscribes from country code change events. 1283 1284**System capability**: SystemCapability.Location.Location.Core 1285 1286**Parameters** 1287 1288 | Name| Type| Mandatory| Description| 1289 | -------- | -------- | -------- | -------- | 1290 | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change.| 1291 | callback | Callback<[CountryCode](#countrycode)> | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 1292 1293**Error codes** 1294 1295For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1296 1297| ID| Error Message| 1298| -------- | ---------------------------------------- | 1299|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1300|801 | Capability not supported. Failed to call ${geoLocationManager.off('countryCodeChange')} due to limited device capabilities. | 1301|3301000 | The location service is unavailable. | 1302|3301500 | Failed to query the area information. | 1303 1304**Example** 1305 1306 ```ts 1307 import { geoLocationManager } from '@kit.LocationKit'; 1308 1309 let callback = (code:geoLocationManager.CountryCode):void => { 1310 console.info('countryCodeChange: ' + JSON.stringify(code)); 1311 } 1312 1313 try { 1314 geoLocationManager.on('countryCodeChange', callback); 1315 geoLocationManager.off('countryCodeChange', callback); 1316 } catch (err) { 1317 console.error("errCode:" + err.code + ", message:" + err.message); 1318 } 1319 ``` 1320 1321 1322## geoLocationManager.getCurrentLocation 1323 1324getCurrentLocation(request: CurrentLocationRequest | SingleLocationRequest, callback: AsyncCallback<Location>): void 1325 1326Obtains the current position. This API uses an asynchronous callback to return the result. 1327 1328**Atomic service API**: This API can be used in atomic services since API version 11. 1329 1330**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1331 1332**System capability**: SystemCapability.Location.Location.Core 1333 1334**Parameters** 1335 1336 | Name| Type| Mandatory| Description| 1337 | -------- | -------- | -------- | -------- | 1338 | request | [CurrentLocationRequest](#currentlocationrequest) | [SingleLocationRequest](#singlelocationrequest12) | Yes| Location request.<br>**SingleLocationRequest** is newly added in API version 12.| 1339 | callback | AsyncCallback<[Location](#location)> | Yes| Callback used to return the result.| 1340 1341**Error codes** 1342 1343For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1344 1345| ID| Error Message| 1346| -------- | ---------------------------------------- | 1347|201 | Permission verification failed. The application does not have the permission required to call the API. | 1348|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1349|801 | Capability not supported. Failed to call ${geoLocationManager.getCurrentLocation} due to limited device capabilities. | 1350|3301000 | The location service is unavailable. | 1351|3301100 | The location switch is off. | 1352|3301200 | Failed to obtain the geographical location. | 1353 1354**Example** 1355 1356 ```ts 1357 import { geoLocationManager } from '@kit.LocationKit'; 1358 import { BusinessError } from '@kit.BasicServicesKit'; 1359 // Method 1: Use CurrentLocationRequest as the input parameter. 1360 let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0}; 1361 let locationChange = (err:BusinessError, location:geoLocationManager.Location):void => { 1362 if (err) { 1363 console.error('locationChanger: err=' + JSON.stringify(err)); 1364 } 1365 if (location) { 1366 console.info('locationChanger: location=' + JSON.stringify(location)); 1367 } 1368 }; 1369 1370 try { 1371 geoLocationManager.getCurrentLocation(requestInfo, locationChange); 1372 } catch (err) { 1373 console.error("errCode:" + err.code + ", message:" + err.message); 1374 } 1375 1376 // Method 2: Use SingleLocationRequest as the input parameter. 1377 let request:geoLocationManager.SingleLocationRequest = {'locatingTimeoutMs': 10000, 'locatingPriority': geoLocationManager.LocatingPriority.PRIORITY_ACCURACY}; 1378 let locationCallback = (err:BusinessError, location:geoLocationManager.Location):void => { 1379 if (err) { 1380 console.error('locationChanger: err=' + JSON.stringify(err)); 1381 } 1382 if (location) { 1383 console.info('locationChanger: location=' + JSON.stringify(location)); 1384 } 1385 }; 1386 1387 try { 1388 geoLocationManager.getCurrentLocation(request, locationCallback); 1389 } catch (err) { 1390 console.error("errCode:" + err.code + ", message:" + err.message); 1391 } 1392 ``` 1393 1394## geoLocationManager.getCurrentLocation 1395 1396getCurrentLocation(callback: AsyncCallback<Location>): void 1397 1398Obtains the current position. This API uses an asynchronous callback to return the result. 1399 1400**Atomic service API**: This API can be used in atomic services since API version 11. 1401 1402**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1403 1404**System capability**: SystemCapability.Location.Location.Core 1405 1406**Parameters** 1407 1408 | Name| Type| Mandatory| Description| 1409 | -------- | -------- | -------- | -------- | 1410 | callback | AsyncCallback<[Location](#location)> | Yes| Callback used to return the result.| 1411 1412**Error codes** 1413 1414For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1415 1416| ID| Error Message| 1417| -------- | ---------------------------------------- | 1418|201 | Permission verification failed. The application does not have the permission required to call the API. | 1419|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1420|801 | Capability not supported. Failed to call ${geoLocationManager.getCurrentLocation} due to limited device capabilities. | 1421|3301000 | The location service is unavailable. | 1422|3301100 | The location switch is off. | 1423|3301200 | Failed to obtain the geographical location. | 1424 1425**Example** 1426 1427 ```ts 1428 import { geoLocationManager } from '@kit.LocationKit'; 1429 import { BusinessError } from '@kit.BasicServicesKit'; 1430 let locationChange = (err:BusinessError, location:geoLocationManager.Location) => { 1431 if (err) { 1432 console.error('locationChanger: err=' + JSON.stringify(err)); 1433 } 1434 if (location) { 1435 console.info('locationChanger: location=' + JSON.stringify(location)); 1436 } 1437 }; 1438 1439 try { 1440 geoLocationManager.getCurrentLocation(locationChange); 1441 } catch (err) { 1442 console.error("errCode:" + err.code + ", message:" + err.message); 1443 } 1444 ``` 1445 1446## geoLocationManager.getCurrentLocation 1447 1448getCurrentLocation(request?: CurrentLocationRequest | SingleLocationRequest): Promise<Location> 1449 1450Obtains the current position. This API uses a promise to return the result. 1451 1452**Atomic service API**: This API can be used in atomic services since API version 11. 1453 1454**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1455 1456**System capability**: SystemCapability.Location.Location.Core 1457 1458**Parameters** 1459 1460 | Name| Type| Mandatory| Description| 1461 | -------- | -------- | -------- | -------- | 1462 | request | [CurrentLocationRequest](#currentlocationrequest) | [SingleLocationRequest](#singlelocationrequest12) | No| Location request.<br>**SingleLocationRequest** is newly added in API version 12.| 1463 1464**Return value** 1465 1466 | Type| Description| 1467 | -------- | -------- | 1468 | Promise<[Location](#location)> | Promise used to return the result.| 1469 1470**Error codes** 1471 1472For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1473 1474| ID| Error Message| 1475| -------- | ---------------------------------------- | 1476|201 | Permission verification failed. The application does not have the permission required to call the API. | 1477|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1478|801 | Capability not supported. Failed to call ${geoLocationManager.getCurrentLocation} due to limited device capabilities. | 1479|3301000 | The location service is unavailable. | 1480|3301100 | The location switch is off. | 1481|3301200 | Failed to obtain the geographical location. | 1482 1483**Example** 1484 1485 ```ts 1486 import { geoLocationManager } from '@kit.LocationKit'; 1487 import { BusinessError } from '@kit.BasicServicesKit'; 1488 1489 // Method 1: Use CurrentLocationRequest as the input parameter. 1490 let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0}; 1491 try { 1492 geoLocationManager.getCurrentLocation(requestInfo).then((result) => { 1493 console.info('current location: ' + JSON.stringify(result)); 1494 }) 1495 .catch((error:BusinessError) => { 1496 console.error('promise, getCurrentLocation: error=' + JSON.stringify(error)); 1497 }); 1498 } catch (err) { 1499 console.error("errCode:" + err.code + ", message:" + err.message); 1500 } 1501 1502 // Method 2: Use SingleLocationRequest as the input parameter. 1503 let request:geoLocationManager.SingleLocationRequest = {'locatingTimeoutMs': 10000, 'locatingPriority': geoLocationManager.LocatingPriority.PRIORITY_ACCURACY}; 1504 try { 1505 geoLocationManager.getCurrentLocation(request).then((result) => { 1506 console.info('current location: ' + JSON.stringify(result)); 1507 }) 1508 .catch((error:BusinessError) => { 1509 console.error('promise, getCurrentLocation: error=' + JSON.stringify(error)); 1510 }); 1511 } catch (err) { 1512 console.error("errCode:" + err.code + ", message:" + err.message); 1513 } 1514 ``` 1515 1516 1517## geoLocationManager.getLastLocation 1518 1519getLastLocation(): Location 1520 1521Obtains the last location. 1522 1523**Atomic service API**: This API can be used in atomic services since API version 11. 1524 1525**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1526 1527**System capability**: SystemCapability.Location.Location.Core 1528 1529**Return value** 1530 1531 | Type| Description| 1532 | -------- | -------- | 1533 | [Location](#location) | Location information.| 1534 1535**Error codes** 1536 1537For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1538 1539| ID| Error Message| 1540| -------- | ---------------------------------------- | 1541|201 | Permission verification failed. The application does not have the permission required to call the API. | 1542|801 | Capability not supported. Failed to call ${geoLocationManager.getLastLocation} due to limited device capabilities. | 1543|3301000 | The location service is unavailable. | 1544|3301100 | The location switch is off. | 1545|3301200 |Failed to obtain the geographical location. | 1546 1547**Example** 1548 1549 ```ts 1550 import { geoLocationManager } from '@kit.LocationKit'; 1551 try { 1552 let location = geoLocationManager.getLastLocation(); 1553 } catch (err) { 1554 console.error("errCode:" + err.code + ", message:" + err.message); 1555 } 1556 ``` 1557 1558 1559## geoLocationManager.isLocationEnabled 1560 1561isLocationEnabled(): boolean 1562 1563Checks whether the location service is enabled. 1564 1565**Atomic service API**: This API can be used in atomic services since API version 11. 1566 1567**System capability**: SystemCapability.Location.Location.Core 1568 1569**Return value** 1570 1571 | Type| Description| 1572 | -------- | -------- | 1573 | boolean | **true**: The location switch is enabled.<br>**false**: The location switch is disabled.| 1574 1575**Error codes** 1576 1577For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1578 1579| ID| Error Message| 1580| -------- | ---------------------------------------- | 1581|801 | Capability not supported. Failed to call ${geoLocationManager.isLocationEnabled} due to limited device capabilities. | 1582|3301000 | The location service is unavailable. | 1583 1584**Example** 1585 1586 ```ts 1587 import { geoLocationManager } from '@kit.LocationKit'; 1588 try { 1589 let locationEnabled = geoLocationManager.isLocationEnabled(); 1590 } catch (err) { 1591 console.error("errCode:" + err.code + ", message:" + err.message); 1592 } 1593 ``` 1594 1595 1596## geoLocationManager.getAddressesFromLocation 1597 1598getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void 1599 1600Converts coordinates into geographic descriptions through reverse geocoding. This API uses an asynchronous callback to return the result. 1601 1602**System capability**: SystemCapability.Location.Location.Geocoder 1603 1604**Parameters** 1605 1606 | Name| Type| Mandatory| Description| 1607 | -------- | -------- | -------- | -------- | 1608 | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.| 1609 | callback | AsyncCallback<Array<[GeoAddress](#geoaddress)>> | Yes| Callback used to return the result.| 1610 1611**Error codes** 1612 1613For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1614 1615| ID| Error Message| 1616| -------- | ---------------------------------------- | 1617|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1618|801 | Capability not supported. Failed to call ${geoLocationManager.getAddressesFromLocation} due to limited device capabilities. | 1619|3301000 | The location service is unavailable. | 1620|3301300 | Reverse geocoding query failed. | 1621 1622**Example** 1623 1624 ```ts 1625 import { geoLocationManager } from '@kit.LocationKit'; 1626 let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; 1627 try { 1628 geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { 1629 if (err) { 1630 console.error('getAddressesFromLocation: err=' + JSON.stringify(err)); 1631 } 1632 if (data) { 1633 console.info('getAddressesFromLocation: data=' + JSON.stringify(data)); 1634 } 1635 }); 1636 } catch (err) { 1637 console.error("errCode:" + err.code + ", message:" + err.message); 1638 } 1639 ``` 1640 1641 1642## geoLocationManager.getAddressesFromLocation 1643 1644getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise<Array<GeoAddress>> 1645 1646Converts coordinates into geographic descriptions through reverse geocoding. This API uses a promise to return the result. 1647 1648**System capability**: SystemCapability.Location.Location.Geocoder 1649 1650**Parameters** 1651 1652 | Name| Type| Mandatory| Description| 1653 | -------- | -------- | -------- | -------- | 1654 | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.| 1655 1656**Return value** 1657 1658 | Type| Description| 1659 | -------- | -------- | 1660 | Promise<Array<[GeoAddress](#geoaddress)>> | Promise used to return the result.| 1661 1662**Error codes** 1663 1664For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1665 1666| ID| Error Message| 1667| -------- | ---------------------------------------- | 1668|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1669|801 | Capability not supported. Failed to call ${geoLocationManager.getAddressesFromLocation} due to limited device capabilities. | 1670|3301000 | The location service is unavailable. | 1671|3301300 | Reverse geocoding query failed. | 1672 1673**Example** 1674 1675 ```ts 1676 import { geoLocationManager } from '@kit.LocationKit'; 1677 import { BusinessError } from '@kit.BasicServicesKit'; 1678 let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; 1679 try { 1680 geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { 1681 console.info('getAddressesFromLocation: ' + JSON.stringify(data)); 1682 }) 1683 .catch((error:BusinessError) => { 1684 console.error('promise, getAddressesFromLocation: error=' + JSON.stringify(error)); 1685 }); 1686 } catch (err) { 1687 console.error("errCode:" + err.code + ", message:" + err.message); 1688 } 1689 ``` 1690 1691 1692## geoLocationManager.getAddressesFromLocationName 1693 1694getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void 1695 1696Converts geographic descriptions into coordinates through geocoding. This API uses an asynchronous callback to return the result. 1697 1698**System capability**: SystemCapability.Location.Location.Geocoder 1699 1700**Parameters** 1701 1702 | Name| Type| Mandatory| Description| 1703 | -------- | -------- | -------- | -------- | 1704 | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.| 1705 | callback | AsyncCallback<Array<[GeoAddress](#geoaddress)>> | Yes| Callback used to return the result.| 1706 1707**Error codes** 1708 1709For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1710 1711| ID| Error Message| 1712| -------- | ---------------------------------------- | 1713|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1714|801 | Capability not supported. Failed to call ${geoLocationManager.getAddressesFromLocationName} due to limited device capabilities. | 1715|3301000 | The location service is unavailable. | 1716|3301400 | Geocoding query failed. | 1717 1718**Example** 1719 1720 ```ts 1721 import { geoLocationManager } from '@kit.LocationKit'; 1722 let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; 1723 try { 1724 geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => { 1725 if (err) { 1726 console.error('getAddressesFromLocationName: err=' + JSON.stringify(err)); 1727 } 1728 if (data) { 1729 console.info('getAddressesFromLocationName: data=' + JSON.stringify(data)); 1730 } 1731 }); 1732 } catch (err) { 1733 console.error("errCode:" + err.code + ", message:" + err.message); 1734 } 1735 ``` 1736 1737 1738## geoLocationManager.getAddressesFromLocationName 1739 1740getAddressesFromLocationName(request: GeoCodeRequest): Promise<Array<GeoAddress>> 1741 1742Converts geographic descriptions into coordinates through geocoding. This API uses an a promise to return the result. 1743 1744**System capability**: SystemCapability.Location.Location.Geocoder 1745 1746**Parameters** 1747 1748 | Name| Type| Mandatory| Description| 1749 | -------- | -------- | -------- | -------- | 1750 | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.| 1751 1752**Return value** 1753 1754 | Type| Description| 1755 | -------- | -------- | 1756 | Promise<Array<[GeoAddress](#geoaddress)>> | Promise used to return the result.| 1757 1758**Error codes** 1759 1760For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1761 1762| ID| Error Message| 1763| -------- | ---------------------------------------- | 1764|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1765|801 | Capability not supported. Failed to call ${geoLocationManager.getAddressesFromLocationName} due to limited device capabilities. | 1766|3301000 | The location service is unavailable. | 1767|3301400 | Geocoding query failed. | 1768 1769**Example** 1770 1771 ```ts 1772 import { geoLocationManager } from '@kit.LocationKit'; 1773 import { BusinessError } from '@kit.BasicServicesKit'; 1774 let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; 1775 try { 1776 geoLocationManager.getAddressesFromLocationName(geocodeRequest).then((result) => { 1777 console.info('getAddressesFromLocationName: ' + JSON.stringify(result)); 1778 }) 1779 .catch((error:BusinessError) => { 1780 console.error('promise, getAddressesFromLocationName: error=' + JSON.stringify(error)); 1781 }); 1782 } catch (err) { 1783 console.error("errCode:" + err.code + ", message:" + err.message); 1784 } 1785 ``` 1786 1787## geoLocationManager.isGeocoderAvailable 1788 1789isGeocoderAvailable(): boolean 1790 1791Checks whether the geocoding and reverse geocoding services are available. 1792 1793**System capability**: SystemCapability.Location.Location.Geocoder 1794 1795**Return value** 1796 1797 | Type| Description| 1798 | -------- | -------- | 1799 | boolean | **true**: The geocoding and reverse geocoding services are available.<br>**false**: The geocoding and reverse geocoding services are unavailable.| 1800 1801**Error codes** 1802 1803For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1804 1805| ID| Error Message| 1806| -------- | ---------------------------------------- | 1807|801 | Capability not supported. Failed to call ${geoLocationManager.isGeocoderAvailable} due to limited device capabilities. | 1808|3301000 | The location service is unavailable. | 1809 1810**Example** 1811 1812 ```ts 1813 import { geoLocationManager } from '@kit.LocationKit'; 1814 try { 1815 let isAvailable = geoLocationManager.isGeocoderAvailable(); 1816 } catch (err) { 1817 console.error("errCode:" + err.code + ", message:" + err.message); 1818 } 1819 ``` 1820 1821 1822## geoLocationManager.getCachedGnssLocationsSize 1823 1824getCachedGnssLocationsSize(callback: AsyncCallback<number>): void 1825 1826Obtains 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. This API uses an asynchronous callback to return the result. 1827 1828**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1829 1830**System capability**: SystemCapability.Location.Location.Gnss 1831 1832**Parameters** 1833 1834 | Name| Type| Mandatory| Description| 1835 | -------- | -------- | -------- | -------- | 1836 | callback | AsyncCallback<number> | Yes| Callback used to return the result.| 1837 1838**Error codes** 1839 1840For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1841 1842| ID| Error Message| 1843| -------- | ---------------------------------------- | 1844|201 | Permission verification failed. The application does not have the permission required to call the API. | 1845|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1846|801 | Capability not supported. Failed to call ${geoLocationManager.getCachedGnssLocationsSize} due to limited device capabilities. | 1847|3301000 | The location service is unavailable. | 1848|3301100 | The location switch is off. | 1849 1850**Example** 1851 1852 ```ts 1853 import { geoLocationManager } from '@kit.LocationKit'; 1854 try { 1855 geoLocationManager.getCachedGnssLocationsSize((err, size) => { 1856 if (err) { 1857 console.error('getCachedGnssLocationsSize: err=' + JSON.stringify(err)); 1858 } 1859 if (size) { 1860 console.info('getCachedGnssLocationsSize: size=' + JSON.stringify(size)); 1861 } 1862 }); 1863 } catch (err) { 1864 console.error("errCode:" + err.code + ", message:" + err.message); 1865 } 1866 ``` 1867 1868 1869## geoLocationManager.getCachedGnssLocationsSize 1870 1871getCachedGnssLocationsSize(): Promise<number> 1872 1873Obtains 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. This API uses a promise to return the result. 1874 1875**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1876 1877**System capability**: SystemCapability.Location.Location.Gnss 1878 1879**Return value** 1880 1881 | Type| Description| 1882 | -------- | -------- | 1883 | Promise<number> | Promise used to return the result.| 1884 1885**Error codes** 1886 1887For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1888 1889| ID| Error Message| 1890| -------- | ---------------------------------------- | 1891|201 | Permission verification failed. The application does not have the permission required to call the API. | 1892|801 | Capability not supported. Failed to call ${geoLocationManager.getCachedGnssLocationsSize} due to limited device capabilities. | 1893|3301000 | The location service is unavailable. | 1894|3301100 | The location switch is off. | 1895 1896**Example** 1897 1898 ```ts 1899 import { geoLocationManager } from '@kit.LocationKit'; 1900 import { BusinessError } from '@kit.BasicServicesKit'; 1901 try { 1902 geoLocationManager.getCachedGnssLocationsSize().then((result) => { 1903 console.info('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result)); 1904 }) 1905 .catch((error:BusinessError) => { 1906 console.error('promise, getCachedGnssLocationsSize: error=' + JSON.stringify(error)); 1907 }); 1908 } catch (err) { 1909 console.error("errCode:" + err.code + ", message:" + err.message); 1910 } 1911 ``` 1912 1913 1914## geoLocationManager.flushCachedGnssLocations 1915 1916flushCachedGnssLocations(callback: AsyncCallback<void>): void 1917 1918Obtains 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. This API uses an asynchronous callback to return the result. 1919 1920**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1921 1922**System capability**: SystemCapability.Location.Location.Gnss 1923 1924**Parameters** 1925 1926 | Name| Type| Mandatory| Description| 1927 | -------- | -------- | -------- | -------- | 1928 | callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1929 1930**Error codes** 1931 1932For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1933 1934| ID| Error Message| 1935| -------- | ---------------------------------------- | 1936|201 | Permission verification failed. The application does not have the permission required to call the API. | 1937|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1938|801 | Capability not supported. Failed to call ${geoLocationManager.flushCachedGnssLocations} due to limited device capabilities. | 1939|3301000 | The location service is unavailable. | 1940|3301100 | The location switch is off. | 1941|3301200 | Failed to obtain the geographical location. | 1942 1943**Example** 1944 1945 ```ts 1946 import { geoLocationManager } from '@kit.LocationKit'; 1947 try { 1948 geoLocationManager.flushCachedGnssLocations((err) => { 1949 if (err) { 1950 console.error('flushCachedGnssLocations: err=' + JSON.stringify(err)); 1951 } 1952 }); 1953 } catch (err) { 1954 console.error("errCode:" + err.code + ", message:" + err.message); 1955 } 1956 ``` 1957 1958 1959## geoLocationManager.flushCachedGnssLocations 1960 1961flushCachedGnssLocations(): Promise<void> 1962 1963Obtains 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. This API uses a promise to return the result. 1964 1965**Permission required**: ohos.permission.APPROXIMATELY_LOCATION 1966 1967**System capability**: SystemCapability.Location.Location.Gnss 1968 1969**Return value** 1970 1971 | Type| Description| 1972 | -------- | -------- | 1973 | Promise<void> | Promise that returns no value.| 1974 1975**Error codes** 1976 1977For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 1978 1979| ID| Error Message| 1980| -------- | ---------------------------------------- | 1981|201 | Permission verification failed. The application does not have the permission required to call the API. | 1982|801 | Capability not supported. Failed to call ${geoLocationManager.flushCachedGnssLocations} due to limited device capabilities. | 1983|3301000 | The location service is unavailable. | 1984|3301100 | The location switch is off. | 1985|3301200 | Failed to obtain the geographical location. | 1986 1987**Example** 1988 1989 ```ts 1990 import { geoLocationManager } from '@kit.LocationKit'; 1991 import { BusinessError } from '@kit.BasicServicesKit'; 1992 try { 1993 geoLocationManager.flushCachedGnssLocations().then(() => { 1994 console.info('promise, flushCachedGnssLocations success'); 1995 }) 1996 .catch((error:BusinessError) => { 1997 console.error('promise, flushCachedGnssLocations: error=' + JSON.stringify(error)); 1998 }); 1999 } catch (err) { 2000 console.error("errCode:" + err.code + ", message:" + err.message); 2001 } 2002 ``` 2003 2004 2005## geoLocationManager.sendCommand 2006 2007sendCommand(command: LocationCommand, callback: AsyncCallback<void>): void 2008 2009Sends an extended command to the location subsystem. This API uses an asynchronous callback to return the result. 2010 2011**System capability**: SystemCapability.Location.Location.Core 2012 2013**Parameters** 2014 2015 | Name| Type| Mandatory| Description| 2016 | -------- | -------- | -------- | -------- | 2017 | command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.| 2018 | callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 2019 2020**Error codes** 2021 2022For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 2023 2024| ID| Error Message| 2025| -------- | ---------------------------------------- | 2026|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2027|801 | Capability not supported. Failed to call ${geoLocationManager.sendCommand} due to limited device capabilities. | 2028|3301000 | The location service is unavailable. | 2029 2030**Example** 2031 2032 ```ts 2033 import { geoLocationManager } from '@kit.LocationKit'; 2034 let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"}; 2035 try { 2036 geoLocationManager.sendCommand(requestInfo, (err) => { 2037 if (err) { 2038 console.error('sendCommand: err=' + JSON.stringify(err)); 2039 } 2040 }); 2041 } catch (err) { 2042 console.error("errCode:" + err.code + ", message:" + err.message); 2043 } 2044 ``` 2045 2046 2047## geoLocationManager.sendCommand 2048 2049sendCommand(command: LocationCommand): Promise<void> 2050 2051Sends an extended command to the location subsystem. This API uses a promise to return the result. 2052 2053**System capability**: SystemCapability.Location.Location.Core 2054 2055**Parameters** 2056 2057 | Name| Type| Mandatory| Description| 2058 | -------- | -------- | -------- | -------- | 2059 | command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.| 2060 2061**Return value** 2062 2063 | Type| Description| 2064 | -------- | -------- | 2065 | Promise<void> | Promise that returns no value.| 2066 2067**Error codes** 2068 2069For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 2070 2071| ID| Error Message| 2072| -------- | ---------------------------------------- | 2073|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2074|801 | Capability not supported. Failed to call ${geoLocationManager.sendCommand} due to limited device capabilities. | 2075|3301000 | The location service is unavailable. | 2076 2077**Example** 2078 2079 ```ts 2080 import { geoLocationManager } from '@kit.LocationKit'; 2081 import { BusinessError } from '@kit.BasicServicesKit'; 2082 let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"}; 2083 try { 2084 geoLocationManager.sendCommand(requestInfo).then(() => { 2085 console.info('promise, sendCommand success'); 2086 }) 2087 .catch((error:BusinessError) => { 2088 console.error('promise, sendCommand: error=' + JSON.stringify(error)); 2089 }); 2090 } catch (err) { 2091 console.error("errCode:" + err.code + ", message:" + err.message); 2092 } 2093 ``` 2094 2095 2096## geoLocationManager.getCountryCode 2097 2098getCountryCode(callback: AsyncCallback<CountryCode>): void 2099 2100Obtains the current country code. This API uses an asynchronous callback to return the result. 2101 2102**System capability**: SystemCapability.Location.Location.Core 2103 2104**Parameters** 2105 2106 | Name| Type| Mandatory| Description| 2107 | -------- | -------- | -------- | -------- | 2108 | callback | AsyncCallback<[CountryCode](#countrycode)> | Yes| Callback used to return the result.| 2109 2110**Error codes** 2111 2112For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 2113 2114| ID| Error Message| 2115| -------- | ---------------------------------------- | 2116|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2117|801 | Capability not supported. Failed to call ${geoLocationManager.getCountryCode} due to limited device capabilities. | 2118|3301000 | The location service is unavailable. | 2119|3301500 | Failed to query the area information.| 2120 2121**Example** 2122 2123 ```ts 2124 import { geoLocationManager } from '@kit.LocationKit'; 2125 try { 2126 geoLocationManager.getCountryCode((err, result) => { 2127 if (err) { 2128 console.error('getCountryCode: err=' + JSON.stringify(err)); 2129 } 2130 if (result) { 2131 console.info('getCountryCode: result=' + JSON.stringify(result)); 2132 } 2133 }); 2134 } catch (err) { 2135 console.error("errCode:" + err.code + ", message:" + err.message); 2136 } 2137 ``` 2138 2139 2140## geoLocationManager.getCountryCode 2141 2142getCountryCode(): Promise<CountryCode> 2143 2144Obtains the current country code. This API uses a promise to return the result. 2145 2146**System capability**: SystemCapability.Location.Location.Core 2147 2148**Return value** 2149 2150 | Type| Description| 2151 | -------- | -------- | 2152 | Promise<[CountryCode](#countrycode)> | Promise used to return the result.| 2153 2154**Error codes** 2155 2156For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 2157 2158| ID| Error Message| 2159| -------- | ---------------------------------------- | 2160|801 | Capability not supported. Failed to call ${geoLocationManager.getCountryCode} due to limited device capabilities. | 2161|3301000 | The location service is unavailable. | 2162|3301500 | Failed to query the area information.| 2163 2164**Example** 2165 2166 ```ts 2167 import { geoLocationManager } from '@kit.LocationKit'; 2168 import { BusinessError } from '@kit.BasicServicesKit'; 2169 try { 2170 geoLocationManager.getCountryCode() 2171 .then((result) => { 2172 console.info('promise, getCountryCode: result=' + JSON.stringify(result)); 2173 }) 2174 .catch((error:BusinessError) => { 2175 console.error('promise, getCountryCode: error=' + JSON.stringify(error)); 2176 }); 2177 } catch (err) { 2178 console.error("errCode:" + err.code + ", message:" + err.message); 2179 } 2180 ``` 2181 2182## geoLocationManager.addGnssGeofence<sup>12+</sup> 2183 2184addGnssGeofence(fenceRequest: GnssGeofenceRequest): Promise<number> 2185 2186Adds a GNSS geofence and subscribes to geofence transition events. This API uses a promise to return the result. 2187 2188The application can pass a callback to [GnssGeofenceRequest](#gnssgeofencerequest12) to receive geofence transition events. It can also pass [NotificationRequest](../apis-notification-kit/js-apis-notification.md#notificationrequest) so that a notification is displayed when a geofence transition event occurs. 2189 2190This 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. 2191 2192**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 2193 2194**System capability**: SystemCapability.Location.Location.Geofence 2195 2196**Parameters** 2197 2198 | Name| Type| Mandatory| Description| 2199 | -------- | -------- | -------- | -------- | 2200 | fenceRequest | [GnssGeofenceRequest](#gnssgeofencerequest12) | Yes| Geofence request.<br>It includes the geofence information, list of geofence transition events and notifications, and callback used to receive geofence transition events.| 2201 2202**Return value** 2203 2204 | Type| Description| 2205 | -------- | -------- | 2206 | Promise<number> | Promise used to return the result.| 2207 2208**Error codes** 2209 2210For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 2211 2212| ID| Error Message| 2213| -------- | ---------------------------------------- | 2214|201 | Permission verification failed. The application does not have the permission required to call the API. | 2215|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2216|801 | Capability not supported. Failed to call ${geoLocationManager.addGnssGeofence} due to limited device capabilities. | 2217|3301000 | The location service is unavailable.| 2218|3301100 | The location switch is off.| 2219|3301601 | The number of geofences exceeds the maximum.| 2220 2221**Example** 2222 2223 ```ts 2224 import { geoLocationManager } from '@kit.LocationKit'; 2225 import { BusinessError } from '@kit.BasicServicesKit'; 2226 import { notificationManager } from '@kit.NotificationKit'; 2227 // Create a geofence. 2228 let geofence: geoLocationManager.Geofence = { 2229 "latitude": 34.12, "longitude": 124.11, "radius": 10000.0, "expiration": 10000.0 2230 } 2231 // Specify the types of geofence transition events to listen for. Geofence entry and exit events are used as an example. 2232 let transitionStatusList: Array<geoLocationManager.GeofenceTransitionEvent> = [ 2233 geoLocationManager.GeofenceTransitionEvent.GEOFENCE_TRANSITION_EVENT_ENTER, 2234 geoLocationManager.GeofenceTransitionEvent.GEOFENCE_TRANSITION_EVENT_EXIT, 2235 ]; 2236 // Create a notification object for GEOFENCE_TRANSITION_EVENT_ENTER. 2237 let notificationRequest1: notificationManager.NotificationRequest = { 2238 id: 1, 2239 content: { 2240 notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 2241 normal: { 2242 title: "Geofence Notification", 2243 text: "Geofence Entry", 2244 additionalText: "" 2245 } 2246 } 2247 }; 2248 // Create a notification object for GEOFENCE_TRANSITION_EVENT_EXIT. 2249 let notificationRequest2: notificationManager.NotificationRequest = { 2250 id: 2, 2251 content: { 2252 notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 2253 normal: { 2254 title: "Geofence Notification", 2255 text:'Geofence Exit', 2256 additionalText: "" 2257 } 2258 } 2259 }; 2260 // Save the created notification objects to Array in the same sequence as in transitionStatusList. 2261 let notificationRequestList: Array<notificationManager.NotificationRequest> = 2262 [notificationRequest1, notificationRequest2]; 2263 // Construct a gnssGeofenceRequest object. 2264 let gnssGeofenceRequest: geoLocationManager.GnssGeofenceRequest = { 2265 // Geofence attributes, including the circle center and radius. 2266 geofence: geofence, 2267 // Specify the types of geofence transition events to listen for. 2268 monitorTransitionEvents: transitionStatusList, 2269 // Specify the notification objects for geofence transition events. This parameter is optional. 2270 notifications: notificationRequestList, 2271 // Specify the callback used to receive geofence transition events. 2272 geofenceTransitionCallback: (err : BusinessError, transition : geoLocationManager.GeofenceTransition) => { 2273 if (err) { 2274 console.error('geofenceTransitionCallback: err=' + JSON.stringify(err)); 2275 } 2276 if (transition) { 2277 console.info("GeofenceTransition: %{public}s", JSON.stringify(transition)); 2278 } 2279 } 2280 } 2281 try { 2282 // Add a geofence. 2283 geoLocationManager.addGnssGeofence(gnssGeofenceRequest).then((id) => { 2284 // Obtain the geofence ID after the geofence is successfully added. 2285 console.info("addGnssGeofence success, fence id: " + id); 2286 let fenceId = id; 2287 }).catch((err: BusinessError) => { 2288 console.error("addGnssGeofence failed, promise errCode:" + (err as BusinessError).code + 2289 ",errMessage:" + (err as BusinessError).message); 2290 }); 2291 } catch(error) { 2292 console.error("addGnssGeofence failed, err:" + JSON.stringify(error)); 2293 } 2294 ``` 2295 2296 2297## geoLocationManager.removeGnssGeofence<sup>12+</sup> 2298 2299removeGnssGeofence(geofenceId: number): Promise<void> 2300 2301Removes a GNSS geofence and unsubscribes from geofence transition events. This API uses a promise to return the result. 2302 2303This 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. 2304 2305**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 2306 2307**System capability**: SystemCapability.Location.Location.Geofence 2308 2309**Parameters** 2310 2311 | Name| Type| Mandatory| Description| 2312 | -------- | -------- | -------- | -------- | 2313 | geofenceId | number | Yes| GNSS geofence ID.| 2314 2315**Return value** 2316 2317 | Type| Description| 2318 | -------- | -------- | 2319 | Promise<void> | Promise that that returns no value.| 2320 2321**Error codes** 2322 2323For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 2324 2325| ID| Error Message| 2326| -------- | ---------------------------------------- | 2327|201 | Permission verification failed. The application does not have the permission required to call the API. | 2328|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2329|801 | Capability not supported. Failed to call ${geoLocationManager.removeGnssGeofence} due to limited device capabilities. | 2330|3301000 | The location service is unavailable. | 2331|3301602 | Failed to delete a geofence due to an incorrect ID. | 2332 2333**Example** 2334 2335 ```ts 2336 import { geoLocationManager } from '@kit.LocationKit'; 2337 import { BusinessError } from '@kit.BasicServicesKit'; 2338 // fenceId is obtained after geoLocationManager.addGnssGeofence is successfully executed. 2339 let fenceId = 1; 2340 try { 2341 geoLocationManager.removeGnssGeofence(fenceId).then(() => { 2342 console.info("removeGnssGeofence success fenceId:" + fenceId); 2343 }).catch((error : BusinessError) => { 2344 console.error("removeGnssGeofence: error=" + JSON.stringify(error)); 2345 }); 2346 } catch(error) { 2347 console.error("removeGnssGeofence: error=" + JSON.stringify(error)); 2348 } 2349 ``` 2350 2351 2352## geoLocationManager.getGeofenceSupportedCoordTypes<sup>12+</sup> 2353 2354getGeofenceSupportedCoordTypes(): Array<CoordinateSystemType> 2355 2356Obtains the list of supported coordinate systems. 2357 2358**System capability**: SystemCapability.Location.Location.Geofence 2359 2360**Return value** 2361 2362 | Type| Description| 2363 | -------- | -------- | 2364 | Array<[CoordinateSystemType](#coordinatesystemtype12)> | List of supported coordinate systems.| 2365 2366**Error codes** 2367 2368For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 2369 2370| ID| Error Message| 2371| -------- | ---------------------------------------- | 2372|801 | Capability not supported. Failed to call ${geoLocationManager.getGeofenceSupportedCoordTypes} due to limited device capabilities. | 2373|3301000 | The location service is unavailable. | 2374 2375**Example** 2376 2377 ```ts 2378 import { geoLocationManager } from '@kit.LocationKit'; 2379 try { 2380 let supportedCoordTypes: Array<geoLocationManager.CoordinateSystemType> = geoLocationManager.getGeofenceSupportedCoordTypes(); 2381 console.info("getGeofenceSupportedCoordTypes return:" + JSON.stringify(supportedCoordTypes)); 2382 } catch(error) { 2383 console.error("getGeofenceSupportedCoordTypes: error=" + JSON.stringify(error)); 2384 } 2385 ``` 2386 2387 2388## geoLocationManager.getCurrentWifiBssidForLocating<sup>14+</sup> 2389 2390getCurrentWifiBssidForLocating(): string 2391 2392Obtains the Basic Service Set Identifier (BSSID) of the connected Wi-Fi access point (AP). 2393 2394**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 2395 2396**System capability**: SystemCapability.Location.Location.Core 2397 2398**Return value** 2399 2400 | Type| Description| 2401 | -------- | -------- | 2402 | string | Wi-Fi Bssid | 2403 2404**Error codes** 2405 2406For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 2407 2408| ID| Error Message| 2409| -------- | ---------------------------------------- | 2410|201 | Permission verification failed. The application does not have the permission required to call the API. | 2411|801 | Capability not supported. Failed to call ${geoLocationManager.getCurrentWifiBssidForLocating()} due to limited device capabilities. | 2412|3301000 | The location service is unavailable. | 2413|3301100 | The location switch is off. | 2414|3301900 | Failed to obtain the BSSID of the Wi-Fi hotspot. The Wi-Fi network is not connected. | 2415 2416**Example** 2417 2418 ```ts 2419 import { geoLocationManager } from '@kit.LocationKit'; 2420 try { 2421 let bssid: string = geoLocationManager.getCurrentWifiBssidForLocating(); 2422 console.info("get wifi bssid:" + bssid); 2423 } catch(error) { 2424 console.error("getCurrentWifiBssidForLocating: errCode" + error.code + ", errMessage" + error.message); 2425 } 2426 ``` 2427 2428 2429## geoLocationManager.on('bluetoothScanResultChange')<sup>16+</sup> 2430 2431on(type: 'bluetoothScanResultChange', callback: Callback<BluetoothScanResult>): void 2432 2433Enables listening for Bluetooth scan information reporting events. This API uses an asynchronous callback to return the result. 2434 2435<!--RP1--><!--RP1End--> 2436 2437This API starts a Bluetooth scan. To avoid high power consumption, you need to call [geoLocationManager.off('bluetoothScanResultChange')](#geolocationmanageroffbluetoothscanresultchange16) to stop Bluetooth scan at a proper time. 2438 2439Currently, only BLE device scanning is supported. 2440 2441**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION 2442 2443**System capability**: SystemCapability.Location.Location.Core 2444 2445**Parameters** 2446 2447 | Name| Type| Mandatory| Description| 2448 | -------- | -------- | -------- | -------- | 2449 | type | string | Yes| Event type. The value **bluetoothScanResultChange** indicates the Bluetooth scan information reporting event.| 2450 | callback | Callback<[BluetoothScanResult](#bluetoothscanresult16)> | Yes| Callback used to return the Bluetooth scan information.| 2451 2452**Error codes** 2453 2454For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 2455 2456| ID| Error Message| 2457| -------- | ---------------------------------------- | 2458|201 | Permission verification failed. The application does not have the permission required to call the API. | 2459|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2460|801 | Capability not supported. Failed to call ${geoLocationManager.on('bluetoothScanResultChange')} due to limited device capabilities. | 2461|3301000 | The location service is unavailable. | 2462|3301100 | The location switch is off. | 2463 2464**Example** 2465 2466 ```ts 2467 import { geoLocationManager } from '@kit.LocationKit'; 2468 2469 2470 let callback = (result: geoLocationManager.BluetoothScanResult):void => { 2471 console.info('bluetoothScanResultChange: ' + JSON.stringify(result)); 2472 }; 2473 try { 2474 geoLocationManager.on('bluetoothScanResultChange', callback); 2475 } catch (err) { 2476 console.error("errCode:" + err.code + ", message:" + err.message); 2477 } 2478 2479 ``` 2480 2481 2482## geoLocationManager.off('bluetoothScanResultChange')<sup>16+</sup> 2483 2484off(type: 'bluetoothScanResultChange', callback?: Callback<BluetoothScanResult>): void 2485 2486Disables listening for Bluetooth scan information reporting events. 2487 2488**Required permissions**: ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION 2489 2490**System capability**: SystemCapability.Location.Location.Core 2491 2492**Parameters** 2493 2494 | Name| Type| Mandatory| Description| 2495 | -------- | -------- | -------- | -------- | 2496 | type | string | Yes| Event type. The value **bluetoothScanResultChange** indicates the Bluetooth scan information reporting event.| 2497 | callback | Callback<[BluetoothScanResult](#bluetoothscanresult16)> | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.| 2498 2499**Error codes** 2500 2501For details about the error codes, see [Location Error Codes]](errorcode-geoLocationManager.md). 2502 2503| ID| Error Message| 2504| -------- | ---------------------------------------- | 2505|201 | Permission verification failed. The application does not have the permission required to call the API. | 2506|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2507|801 | Capability not supported. Failed to call ${geoLocationManager.off('bluetoothScanResultChange')} due to limited device capabilities. | 2508|3301000 | The location service is unavailable. | 2509 2510**Example** 2511 2512 ```ts 2513 import { geoLocationManager } from '@kit.LocationKit'; 2514 2515 let callback = (result: geoLocationManager.BluetoothScanResult):void => { 2516 console.info('bluetoothScanResultChange: ' + JSON.stringify(result)); 2517 }; 2518 try { 2519 geoLocationManager.on('bluetoothScanResultChange', callback); 2520 geoLocationManager.off('bluetoothScanResultChange', callback); 2521 } catch (err) { 2522 console.error("errCode:" + err.code + ", message:" + err.message); 2523 } 2524 ``` 2525