• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.geoLocationManager (位置服务)
2
3位置服务提供GNSS定位、网络定位(蜂窝基站、WLAN、蓝牙定位技术)、地理编码、逆地理编码、国家码和地理围栏等基本功能。
4
5使用位置服务时请打开设备“位置”开关。如果“位置”开关关闭并且代码未设置捕获异常,可能导致应用异常。
6
7> **说明:**
8>
9> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
10> 本模块能力仅支持WGS-84坐标系。
11
12## 申请权限
13
14请参考[申请位置权限开发指导](../../device/location/location-permission-guidelines.md#开发步骤)。
15
16
17## 导入模块
18
19```ts
20import { geoLocationManager } from '@kit.LocationKit';
21```
22
23
24## ReverseGeoCodeRequest
25
26逆地理编码请求参数。
27
28**系统能力**:SystemCapability.Location.Location.Geocoder
29
30| 名称 | 类型 | 只读 | 可选 | 说明 |
31| -------- | -------- | -------- | -------- | -------- |
32| locale | string | 否 | 是 | 指定位置描述信息的语言,“zh”代表中文,“en”代表英文。默认值从设置中的“语言和地区”获取。 |
33| country<sup>12+</sup> | string | 否 | 是 | 限制查询结果在指定的国家内,采用ISO 3166-1 alpha-2 。“CN”代表中国。默认值从设置中的“语言和地区”获取。 |
34| latitude | number | 否 | 否 | 表示纬度信息,正值表示北纬,负值表示南纬。取值范围为-90到90。仅支持WGS84坐标系。 |
35| longitude | number | 否 | 否 | 表示经度信息,正值表示东经,负值表示西经。取值范围为-180到180。仅支持WGS84坐标系。 |
36| maxItems | number | 否 | 是 | 指定返回位置信息的最大个数。取值范围为大于等于0,推荐该值小于10。默认值是1。 |
37
38
39## GeoCodeRequest
40
41地理编码请求参数。
42
43**系统能力**:SystemCapability.Location.Location.Geocoder
44
45| 名称 | 类型 | 只读 | 可选 | 说明 |
46| -------- | -------- | -------- | -------- | -------- |
47| locale | string | 否 | 是 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。默认值从设置中的“语言和地区”获取。 |
48| country<sup>12+</sup> | string | 否 | 是 | 限制查询结果在指定的国家内,采用ISO 3166-1 alpha-2 。“CN”代表中国。默认值从设置中的“语言和地区”获取。 |
49| description | string | 否 | 否 | 表示位置信息描述,如“上海市浦东新区xx路xx号”。 |
50| maxItems | number | 否 | 是 | 表示返回位置信息的最大个数。取值范围为大于等于0,推荐该值小于10。默认值是1。 |
51| minLatitude | number | 否 | 是 | 表示最小纬度信息,与下面三个参数一起,表示一个经纬度范围。取值范围为-90到90。仅支持WGS84坐标系。如果该参数有值时,下面三个参数必填。 |
52| minLongitude | number | 否 | 是 | 表示最小经度信息。取值范围为-180到180。仅支持WGS84坐标系。 |
53| maxLatitude | number | 否 | 是 | 表示最大纬度信息。取值范围为-90到90。仅支持WGS84坐标系。 |
54| maxLongitude | number | 否 | 是 | 表示最大经度信息。取值范围为-180到180。仅支持WGS84坐标系。 |
55
56
57## GeoAddress
58
59地理编码地址信息。
60
61**系统能力**:SystemCapability.Location.Location.Geocoder
62
63| 名称 | 类型 | 只读 | 可选 | 说明 |
64| -------- | -------- | -------- | -------- | -------- |
65| latitude | number | 否 | 是  | 表示纬度信息,正值表示北纬,负值表示南纬。取值范围为-90到90。仅支持WGS84坐标系。 |
66| longitude | number | 否 | 是  | 表示经度信息,正值表示东经,负值表是西经。取值范围为-180到180。仅支持WGS84坐标系。 |
67| locale | string | 否 | 是  | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
68| placeName | string | 否 | 是  | 表示详细地址信息。 |
69| countryCode | string | 否 | 是  | 表示国家码信息。 |
70| countryName | string | 否 | 是 | 表示国家信息。 |
71| administrativeArea | string | 否 | 是 | 表示国家以下的一级行政区,一般是省/州。 |
72| subAdministrativeArea | string | 否 | 是 | 表示国家以下的二级行政区,一般是市。 |
73| locality | string | 否 | 是 | 表示城市信息,一般是市。 |
74| subLocality | string | 否 | 是 | 表示子城市信息,一般是区/县。 |
75| roadName | string | 否 | 是 | 表示路名信息。 |
76| subRoadName | string | 否 | 是 | 表示子路名信息。 |
77| premises | string | 否 | 是 | 表示门牌号信息。 |
78| postalCode | string | 否 | 是 | 表示邮政编码信息。 |
79| phoneNumber | string | 否 | 是 | 表示联系方式信息。 |
80| addressUrl | string | 否 | 是 | 表示位置信息附件的网址信息。 |
81| descriptions | Array&lt;string&gt; | 否 | 是 | 表示附加的描述信息。目前包含城市编码cityCode(Array下标为0)和区划编码adminCode(Array下标为1),例如["025","320114001"]。 |
82| descriptionsSize | number | 否 | 是 | 表示附加的描述信息数量。取值范围为大于等于0,推荐该值小于10。 |
83
84
85## LocationRequest
86
87位置信息请求参数。
88
89**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
90
91**系统能力**:SystemCapability.Location.Location.Core
92
93| 名称 | 类型 | 只读 | 可选 | 说明 |
94| -------- | -------- | -------- | -------- | -------- |
95| priority | [LocationRequestPriority](#locationrequestpriority) | 否 | 是 | 表示优先级信息。当scenario取值为UNSET时,priority参数生效,否则priority参数不生效;当scenario和priority均取值为UNSET时,无法发起定位请求。取值范围见[LocationRequestPriority](#locationrequestpriority)的定义。 |
96| scenario | [LocationRequestScenario](#locationrequestscenario) | 否 | 是 | 表示场景信息。当scenario取值为UNSET时,priority参数生效,否则priority参数不生效;当scenario和priority均取值为UNSET时,无法发起定位请求。取值范围见[LocationRequestScenario](#locationrequestscenario)的定义。 |
97| timeInterval | number | 否 | 是 |  表示上报位置信息的时间间隔,单位为秒。<br/>取值范围为大于等于0的值。<br/>默认值为对应定位模式下允许的最小时间间隔:<br/>默认值在GNSS定位时为1秒,网络定位时为20秒。<br/>当设置值小于最小间隔时,以最小时间间隔生效。<br/>设置为0时不对时间间隔进行校验,直接上报位置信息。 |
98| distanceInterval | number | 否 | 是 | 表示上报位置信息的距离间隔。单位是米,默认值为0,取值范围为大于等于0。等于0时对位置上报距离间隔无限制。 |
99| maxAccuracy | number | 否 | 是 |  应用向系统请求位置信息时要求的精度值,单位为米。该参数仅在精确位置功能场景(即同时授权了ohos.permission.APPROXIMATELY_LOCATIONohos.permission.LOCATION 权限)下有效,模糊位置功能生效场景(即仅授权了ohos.permission.APPROXIMATELY_LOCATION 权限)下该字段无意义。<br/>该参数生效的情况下,系统会对比GNSS或网络定位服务上报的位置信息与应用的位置信息申请。当位置信息[Location](#location)中的精度值(accuracy)小于等于应用要求的精度值(maxAccuracy)时,位置信息会返回给应用;否则系统将丢弃本次收到的位置信息。<br/>默认值为0,表示不限制位置信息的精度,取值范围为大于等于0。<br/>当scenario为NAVIGATION/TRAJECTORY_TRACKING/CAR_HAILING或者priority为ACCURACY时建议设置maxAccuracy为大于10的值。<br/>当scenario为DAILY_LIFE_SERVICE/NO_POWER或者priority为LOW_POWER/FIRST_FIX时建议设置maxAccuracy为大于100的值。<br/> |
100
101
102## CurrentLocationRequest
103
104当前位置信息请求参数。
105
106**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
107
108**系统能力**:SystemCapability.Location.Location.Core
109
110| 名称 | 类型 | 只读 | 可选 | 说明 |
111| -------- | -------- | -------- | -------- | -------- |
112| priority | [LocationRequestPriority](#locationrequestpriority) | 否 | 是 | 表示优先级信息。当scenario取值为UNSET时,priority参数生效,否则priority参数不生效;当scenario和priority均取值为UNSET时,无法发起定位请求。取值范围见[LocationRequestPriority](#locationrequestpriority)的定义。|
113| scenario | [LocationRequestScenario](#locationrequestscenario) | 否 | 是 | 表示场景信息。当scenario取值为UNSET时,priority参数生效,否则priority参数不生效;当scenario和priority均取值为UNSET时,无法发起定位请求。取值范围见[LocationRequestScenario](#locationrequestscenario)的定义。 |
114| maxAccuracy | number | 否 | 是|  应用向系统请求位置信息时要求的精度值,单位为米。该参数仅在精确位置功能场景(即同时授权了ohos.permission.APPROXIMATELY_LOCATIONohos.permission.LOCATION 权限)下有效,模糊位置功能生效场景(即仅授权了ohos.permission.APPROXIMATELY_LOCATION 权限)下该字段无意义。<br/>该参数生效的情况下,系统会对比GNSS或网络定位服务上报的位置信息与应用的位置信息申请。当位置信息[Location](#location)中的精度值(accuracy)小于等于应用要求的精度值(maxAccuracy)时,位置信息会返回给应用;否则系统将丢弃本次收到的位置信息。<br/>默认值为0,表示不限制位置信息的精度,取值范围为大于等于0。<br/>当scenario为NAVIGATION/TRAJECTORY_TRACKING/CAR_HAILING或者priority为ACCURACY时建议设置maxAccuracy为大于10的值。<br/>当scenario为DAILY_LIFE_SERVICE/NO_POWER或者priority为LOW_POWER/FIRST_FIX时建议设置maxAccuracy为大于100的值。 |
115| timeoutMs | number | 否 | 是 | 表示超时时间,单位是毫秒,最小为1000毫秒。取值范围为大于等于1000。 |
116
117
118## ContinuousLocationRequest<sup>12+</sup>
119
120持续定位的请求参数。
121
122**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
123
124**系统能力**:SystemCapability.Location.Location.Core
125
126| 名称 | 类型 | 只读 | 可选 | 说明 |
127| -------- | -------- | -------- | -------- | -------- |
128| interval | number | 否 | 否 | 表示上报位置信息的时间间隔,单位是秒。默认值为1,取值范围为大于等于0。等于0时对位置上报时间间隔无限制。|
129| locationScenario | [UserActivityScenario](#useractivityscenario12) &#124; [PowerConsumptionScenario](#powerconsumptionscenario12) | 否 | 否 | 表示定位的场景信息。取值范围见[UserActivityScenario](#useractivityscenario12)和[PowerConsumptionScenario](#powerconsumptionscenario12)的定义。 |
130| sportsType<sup>18+</sup> | [SportsType](#sportstype18) | 否 | 是 | 表示运动类型。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。|
131
132
133## SingleLocationRequest<sup>12+</sup>
134
135单次定位的请求参数。
136
137**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
138
139**系统能力**:SystemCapability.Location.Location.Core
140
141| 名称 | 类型 | 只读 | 可选 | 说明 |
142| -------- | -------- | -------- | -------- | -------- |
143| locatingPriority | [LocatingPriority](#locatingpriority12) | 否 | 否 | 表示优先级信息。取值范围见[LocatingPriority](#locatingpriority12)的定义。|
144| locatingTimeoutMs | number | 否 | 否 | 表示超时时间,单位是毫秒,最小为1000毫秒。取值范围为大于等于1000。 |
145
146
147## SatelliteStatusInfo
148
149卫星状态信息。
150
151**系统能力**:SystemCapability.Location.Location.Gnss
152
153| 名称 | 类型 | 只读 | 可选 | 说明 |
154| -------- | -------- | -------- | -------- | -------- |
155| satellitesNumber | number | 否 | 否 | 表示卫星个数。取值范围为大于等于0。 |
156| satelliteIds | Array&lt;number&gt; | 否 | 否 | 表示每个卫星的ID,数组类型。取值范围为大于等于0。 |
157| carrierToNoiseDensitys | Array&lt;number&gt; | 否 | 否 | 表示载波噪声功率谱密度比,即cn0。取值范围为大于0。 |
158| altitudes | Array&lt;number&gt; | 否 | 否 | 表示卫星高度角信息。单位是“度”,取值范围为-90到90。 |
159| azimuths | Array&lt;number&gt; | 否 | 否 | 表示方位角。单位是“度”,取值范围为0到360。 |
160| carrierFrequencies | Array&lt;number&gt; | 否 | 否 | 表示载波频率。单位是Hz,取值范围为大于等于0。 |
161| satelliteConstellation<sup>12+</sup> | Array&lt;[SatelliteConstellationCategory](#satelliteconstellationcategory12)&gt; | 否 | 是 | 表示卫星星座类型。 |
162| satelliteAdditionalInfo<sup>12+</sup> | Array&lt;number&gt; | 否 | 是 | 表示卫星的附加信息。<br/>每个比特位代表不同含义,具体定义参见[SatelliteAdditionalInfo](#satelliteadditionalinfo12)。 |
163
164
165## CachedGnssLocationsRequest
166
167请求订阅GNSS缓存位置上报功能接口的配置参数。
168
169**系统能力**:SystemCapability.Location.Location.Gnss
170
171| 名称 | 类型 | 只读 | 可选 | 说明 |
172| -------- | -------- | -------- | -------- | -------- |
173| reportingPeriodSec | number | 否 | 否 | 表示GNSS缓存位置上报的周期,单位是毫秒。取值范围为大于0。 |
174| wakeUpCacheQueueFull | boolean | 否 | 否  | true表示GNSS芯片底层缓存队列满之后会主动唤醒AP芯片,并把缓存位置上报给应用。<br/>false表示GNSS芯片底层缓存队列满之后不会主动唤醒AP芯片,会把缓存位置直接丢弃。 |
175
176
177## Geofence
178
179GNSS围栏的配置参数。目前只支持圆形围栏。
180
181**系统能力**:SystemCapability.Location.Location.Geofence
182
183| 名称 | 类型 | 只读 | 可选 | 说明 |
184| -------- | -------- | -------- | -------- | -------- |
185| latitude | number | 否 | 否 |表示纬度。取值范围为-90到90。 |
186| longitude | number | 否 |否 | 表示经度。取值范围为-180到180。 |
187| coordinateSystemType<sup>12+</sup> | [CoordinateSystemType](#coordinatesystemtype12) | 否 |是 | 表示地理围栏圆心坐标的坐标系。<br/>APP应先使用[getGeofenceSupportedCoordTypes](#geolocationmanagergetgeofencesupportedcoordtypes12)查询支持的坐标系,然后传入正确的圆心坐标。 |
188| radius | number | 否 |否 | 表示圆形围栏的半径。单位是米,取值范围为大于0。 |
189| expiration | number | 否 |否 | 围栏存活的时间,单位是毫秒。取值范围为大于0。 |
190
191
192## GeofenceRequest
193
194请求添加GNSS围栏消息中携带的参数,包括定位场景和围栏信息。
195
196**系统能力**:SystemCapability.Location.Location.Geofence
197
198| 名称 | 类型 | 只读 | 可选 | 说明 |
199| -------- | -------- | -------- | -------- | -------- |
200| scenario | [LocationRequestScenario](#locationrequestscenario) | 否 | 否  |  表示定位场景。 |
201| geofence |  [Geofence](#geofence)| 否 | 否  |  表示围栏信息。 |
202
203
204## LocationCommand
205
206扩展命令参数。
207
208**系统能力**:SystemCapability.Location.Location.Core
209
210| 名称 | 类型 | 只读 | 可选 | 说明 |
211| -------- | -------- | -------- | -------- | -------- |
212| scenario | [LocationRequestScenario](#locationrequestscenario)  | 否 | 否  | 表示定位场景。 |
213| command | string | 否 | 否  | 扩展命令字符串。 |
214
215
216## Location
217
218位置信息。
219
220**系统能力**:SystemCapability.Location.Location.Core
221
222| 名称 | 类型 | 只读 | 可选 | 说明 |
223| -------- | -------- | -------- | -------- | -------- |
224| latitude | number| 否 | 否 | 表示纬度信息,正值表示北纬,负值表示南纬。取值范围为-90到90。仅支持WGS84坐标系。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
225| longitude | number| 否 | 否 | 表示经度信息,正值表示东经,负值表是西经。取值范围为-180到180。仅支持WGS84坐标系。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
226| altitude | number | 否 | 否 | 表示高度信息,单位米。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
227| accuracy | number | 否 | 否 | 表示精度信息,单位米。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
228| speed | number | 否 | 否 |表示速度信息,单位米每秒。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
229| timeStamp | number | 否 | 否 | 表示位置时间戳,UTC格式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
230| direction | number | 否 | 否 | 表示航向信息。单位是“度”,取值范围为0到360。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
231| timeSinceBoot | number | 否 | 否 | 表示获取位置成功的时间戳,值表示从本次开机到获取位置成功所经过的时间,单位为纳秒。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
232| additions | Array&lt;string&gt;| 否 | 是 | 附加信息。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
233| additionSize | number| 否 | 是 | 附加信息数量。取值范围为大于等于0。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
234| additionsMap<sup>12+</sup> | Map&lt;string, string&gt;| 否 | 是 | 附加信息。具体内容和顺序与additions一致。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
235| altitudeAccuracy<sup>12+</sup> |number | 否 | 是 | 表示高度信息的精度,单位米。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
236| speedAccuracy<sup>12+</sup> | number| 否 | 是 | 表示速度信息的精度,单位米每秒。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
237| directionAccuracy<sup>12+</sup> | number| 否 | 是 | 表示航向信息的精度。单位是“度”,取值范围为0到360。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
238| uncertaintyOfTimeSinceBoot<sup>12+</sup> | number| 否 | 是 | 表示位置时间戳的不确定度。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
239| sourceType<sup>12+</sup> | [LocationSourceType](#locationsourcetype12) | 否 | 是 | 表示定位结果的来源。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
240
241
242## GeofenceTransition<sup>12+</sup>
243
244地理围栏事件信息;包含地理围栏ID和具体的地理围栏事件。
245
246**系统能力**:SystemCapability.Location.Location.Geofence
247
248| 名称 | 类型 | 只读 | 可选 | 说明 |
249| -------- | -------- | -------- | -------- | -------- |
250| geofenceId | number| 否 | 否 | 表示地理围栏ID。 |
251| transitionEvent | [GeofenceTransitionEvent](#geofencetransitionevent12) | 否 | 否 | 表示当前发生的地理围栏事件。 |
252
253
254## GnssGeofenceRequest<sup>12+</sup>
255
256GNSS地理围栏请求参数。
257
258**系统能力**:SystemCapability.Location.Location.Geofence
259
260| 名称 | 类型 | 只读 | 可选 | 说明 |
261| -------- | -------- | -------- | -------- | -------- |
262| geofence | [Geofence](#geofence) | 否 | 否 | 表示地理围栏信息,包含圆形围栏圆心坐标、半径等信息。 |
263| monitorTransitionEvents | Array&lt;[GeofenceTransitionEvent](#geofencetransitionevent12)&gt; | 否 | 否 | 表示APP监听的地理围栏事件列表。 |
264| notifications | Array&lt;[NotificationRequest](../apis-notification-kit/js-apis-notification.md#notificationrequest)&gt; | 否 | 是 | 表示地理围栏事件发生后弹出的通知对象列表。<br/>monitorTransitionEvents与notifications中的顺序要一一对应,例如monitorTransitionEvents[0]为[GeofenceTransitionEvent](#geofencetransitionevent12).GEOFENCE_TRANSITION_EVENT_ENTER,那notifications[0]中就需要填入用户进入围栏时需要弹出的通知对象。 |
265| geofenceTransitionCallback | AsyncCallback&lt;[GeofenceTransition](#geofencetransition12)&gt; | 否 | 否 | 表示用于接收地理围栏事件的回调函数。 |
266
267
268## CountryCode
269
270国家码信息,包含国家码字符串和国家码的来源信息。
271
272**系统能力**:SystemCapability.Location.Location.Core
273
274| 名称 | 类型 | 只读 | 可选 | 说明 |
275| -------- | -------- | -------- | -------- | -------- |
276| country | string | 否 | 否 | 表示国家码字符串。 |
277| type |  [CountryCodeType](#countrycodetype) | 否 | 否 | 表示国家码信息来源。 |
278
279
280## LocationRequestPriority
281
282位置请求中位置信息优先级类型。
283
284**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
285
286**系统能力**:SystemCapability.Location.Location.Core
287
288| 名称 | 值 | 说明 |
289| -------- | -------- | -------- |
290| UNSET | 0x200 | 表示未设置优先级,表示[LocationRequestPriority](#locationrequestpriority)无效。 |
291| ACCURACY | 0x201 | 表示精度优先。<br/>定位精度优先策略主要以GNSS定位技术为主。我们会在GNSS提供稳定位置结果之前使用网络定位技术提供服务。在持续定位过程中,如果超过30秒无法获取GNSS定位结果则使用网络定位技术。对设备的硬件资源消耗较大,功耗较大。 |
292| LOW_POWER | 0x202 | 表示低功耗优先。<br/>低功耗定位优先策略仅使用网络定位技术,在室内和户外场景均可提供定位服务,因为其依赖周边基站、可见WLAN、蓝牙设备的分布情况,定位结果的精度波动范围较大,推荐在对定位结果精度要求不高的场景下使用该策略,可以有效节省设备功耗。 |
293| FIRST_FIX | 0x203 | 表示快速获取位置优先,如果应用希望快速拿到一个位置,可以将优先级设置为该字段。<br/>快速定位优先策略会同时使用GNSS定位和网络定位技术,以便在室内和户外场景下均可以快速获取到位置结果;当各种定位技术都有提供位置结果时,系统会选择其中精度较好的结果返回给应用。因为对各种定位技术同时使用,对设备的硬件资源消耗较大,功耗也较大。 |
294
295
296## LocationRequestScenario
297
298位置请求中定位场景类型。
299
300**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
301
302**系统能力**:SystemCapability.Location.Location.Core
303
304> **说明:**
305>
306> 当使用NAVIGATION/TRAJECTORY_TRACKING/CAR_HAILING场景进行单次定位或持续定位时,我们会在GNSS提供稳定位置结果之前使用网络定位技术提供服务;在持续定位时,如果超过30秒无法获取GNSS定位结果则会使用网络定位技术获取位置。
307
308| 名称 | 值 | 说明 |
309| -------- | -------- | -------- |
310| UNSET | 0x300 | 表示未设置场景信息。<br/>表示[LocationRequestScenario](#locationrequestscenario)字段无效。 |
311| NAVIGATION | 0x301 | 表示导航场景。<br/>适用于在户外获取设备实时位置的场景,如车载、步行导航。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。 |
312| TRAJECTORY_TRACKING | 0x302 | 表示运动轨迹记录场景。<br/>适用于记录用户位置轨迹的场景,如运动类应用记录轨迹功能。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。 |
313| CAR_HAILING | 0x303 | 表示打车场景。<br/>适用于用户出行打车时定位当前位置的场景,如网约车类应用。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。 |
314| DAILY_LIFE_SERVICE | 0x304 | 表示日常服务使用场景。<br/>适用于不需要定位用户精确位置的使用场景,如新闻资讯、网购、点餐类应用。<br/>该场景仅使用网络定位技术提供定位服务,功耗较低。 |
315| NO_POWER | 0x305 | 表示无功耗功场景,这种场景下不会主动触发定位,会在其他应用定位时,才给当前应用返回位置。 |
316
317
318## CountryCodeType
319
320国家码来源类型。
321
322**系统能力**:SystemCapability.Location.Location.Core
323
324| 名称 | 值 | 说明 |
325| -------- | -------- | -------- |
326| COUNTRY_CODE_FROM_LOCALE | 1 | 从全球化模块的语言配置信息中获取到的国家码。 |
327| COUNTRY_CODE_FROM_SIM | 2 | 从SIM卡中获取到的国家码。 |
328| COUNTRY_CODE_FROM_LOCATION | 3 | 基于用户的位置信息,通过逆地理编码查询到的国家码。 |
329| COUNTRY_CODE_FROM_NETWORK | 4 | 从蜂窝网络注册信息中获取到的国家码。 |
330
331
332## CoordinateSystemType<sup>12+</sup>
333
334坐标系类型。
335
336**系统能力**:SystemCapability.Location.Location.Geofence
337
338| 名称 | 值 | 说明 |
339| -------- | -------- | -------- |
340| WGS84 | 1 | World Geodetic System 1984,是为GPS全球定位系统使用而建立的坐标系统。 |
341| GCJ02 | 2 | GCJ-02是由中国国家测绘局制订的地理信息系统的坐标系统。 |
342
343
344## GeofenceTransitionEvent<sup>12+</sup>
345
346地理围栏事件。
347
348**系统能力**:SystemCapability.Location.Location.Geofence
349
350| 名称 | 值 | 说明 |
351| -------- | -------- | -------- |
352| GEOFENCE_TRANSITION_EVENT_ENTER  | 1 | 该事件表示设备从地理围栏外进入地理围栏内。 |
353| GEOFENCE_TRANSITION_EVENT_EXIT  | 2 | 该事件表示设备从地理围栏内退出到地理围栏外。 |
354| GEOFENCE_TRANSITION_EVENT_DWELL   | 4 | 该事件表示设备在地理围栏范围内,且持续徘徊超过10秒。 |
355
356
357## SatelliteConstellationCategory<sup>12+</sup>
358
359卫星星座类型。
360
361**系统能力**:SystemCapability.Location.Location.Gnss
362
363| 名称 | 值 | 说明 |
364| -------- | -------- | -------- |
365| CONSTELLATION_CATEGORY_UNKNOWN   | 0 | 默认值。 |
366| CONSTELLATION_CATEGORY_GPS   | 1 | GPS(Global Positioning System),即全球定位系统,是美国研制发射的一种以人造地球卫星为基础的高精度无线电导航的定位系统。 |
367| CONSTELLATION_CATEGORY_SBAS    | 2 | SBAS(Satellite-Based Augmentation System),即星基增强系统,通过地球静止轨道(GEO)卫星搭载卫星导航增强信号转发器,可以向用户播发星历误差、卫星钟差、电离层延迟等多种修正信息,实现对于原有卫星导航系统定位精度的改进。 |
368| CONSTELLATION_CATEGORY_GLONASS    | 3 | GLONASS(GLOBAL NAVIGATION SATELLITE SYSTEM),是苏联/俄罗斯研制卫星导航系统。 |
369| CONSTELLATION_CATEGORY_QZSS    | 4 | QZSS(Quasi-Zenith Satellite System),即准天顶卫星系统,是以三颗人造卫星透过时间转移完成全球定位系统区域性功能的卫星扩增系统,是日本研发的卫星系统。 |
370| CONSTELLATION_CATEGORY_BEIDOU     | 5 | 北斗卫星导航系统(Beidou Navigation Satellite System)是中国自行研制的全球卫星导航系统。 |
371| CONSTELLATION_CATEGORY_GALILEO     | 6 | GALILEO(Galileo satellite navigation system),即伽利略卫星导航系统,是由欧盟研制和建立的全球卫星导航定位系统。 |
372| CONSTELLATION_CATEGORY_IRNSS     | 7 | IRNSS(Indian Regional Navigation Satellite System),即印度区域导航卫星系统,是一个由印度空间研究组织(ISRO)发展的自由区域型卫星导航系统。 |
373
374
375## SatelliteAdditionalInfo<sup>12+</sup>
376
377卫星附加信息类型。
378
379**系统能力**:SystemCapability.Location.Location.Gnss
380
381| 名称 | 值 | 说明 |
382| -------- | -------- | -------- |
383| SATELLITES_ADDITIONAL_INFO_NULL  | 0 | 默认值。 |
384| SATELLITES_ADDITIONAL_INFO_EPHEMERIS_DATA_EXIST  | 1 | 表示本卫星具有星历数据。 |
385| SATELLITES_ADDITIONAL_INFO_ALMANAC_DATA_EXIST   | 2 | 表示本卫星具有年历数据。 |
386| SATELLITES_ADDITIONAL_INFO_USED_IN_FIX   | 4 | 表示在最新的位置解算中使用了本卫星。 |
387| SATELLITES_ADDITIONAL_INFO_CARRIER_FREQUENCY_EXIST   | 8 | 表示本卫星具有载波频率。 |
388
389
390## PowerConsumptionScenario<sup>12+</sup>
391
392位置请求中的功耗场景类型。
393
394**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
395
396**系统能力**:SystemCapability.Location.Location.Core
397
398| 名称 | 值 | 说明 |
399| -------- | -------- | -------- |
400| HIGH_POWER_CONSUMPTION  | 0x601 | 高功耗。<br/>以GNSS定位技术为主。我们会在GNSS提供稳定位置结果之前使用网络定位技术提供服务;在持续定位时,如果超过30秒无法获取GNSS定位结果则会使用网络定位技术获取位置。对设备的硬件资源消耗较大,功耗较大。 |
401| LOW_POWER_CONSUMPTION  | 0x602 | 低功耗。<br/>适用于对用户位置精度要求不高的使用场景,如新闻资讯、网购、点餐类应用。<br/>该场景仅使用网络定位技术提供定位服务,功耗较低。 |
402| NO_POWER_CONSUMPTION   | 0x603 | 无功耗。<br/>这种场景下不会主动触发定位,会在其他应用定位时,才给当前应用返回位置。  |
403
404
405## UserActivityScenario<sup>12+</sup>
406
407位置请求中的用户活动场景类型。
408
409**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
410
411**系统能力**:SystemCapability.Location.Location.Core
412
413> **说明:**
414>
415> 当使用NAVIGATION/SPORT/TRANSPORT场景进行单次定位或持续定位时,我们会在GNSS提供稳定位置结果之前使用网络定位技术提供服务;在持续定位时,如果超过30秒无法获取GNSS定位结果则会使用网络定位技术获取位置。
416
417| 名称 | 值 | 说明 |
418| -------- | -------- | -------- |
419| NAVIGATION  | 0x401 | 表示导航场景。<br/>适用于在户外获取设备实时位置的场景,如车载、步行导航。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。 |
420| SPORT  | 0x402 | 表示运动场景。<br/>适用于记录用户位置轨迹的场景,如运动类应用记录轨迹功能。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。 |
421| TRANSPORT   | 0x403 | 表示出行场景。<br/>适用于用户出行场景,如打车、乘坐公共交通等场景。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。  |
422| DAILY_LIFE_SERVICE   | 0x404 | 表示日常服务使用场景。<br/>适用于不需要定位用户精确位置的使用场景,如新闻资讯、网购、点餐类应用。<br/>该场景仅使用网络定位技术提供定位服务,功耗较低。  |
423
424
425## LocatingPriority<sup>12+</sup>
426
427单次位置请求中的优先级类型。
428
429**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
430
431**系统能力**:SystemCapability.Location.Location.Core
432
433| 名称 | 值 | 说明 |
434| -------- | -------- | -------- |
435| PRIORITY_ACCURACY  | 0x501 | 表示精度优先。<br/>定位精度优先策略会同时使用GNSS定位和网络定位技术,并把一段时间内精度较好的结果返回给应用;这个时间段长度为[SingleLocationRequest](#singlelocationrequest12).locatingTimeoutMs与“30秒”中的较小者。<br/>对设备的硬件资源消耗较大,功耗较大。  |
436| PRIORITY_LOCATING_SPEED  | 0x502 | 表示快速获取位置优先,如果应用希望快速拿到一个位置,可以将优先级设置为该类型。<br/>快速定位优先策略会同时使用GNSS定位和网络定位技术,以便在室内和户外场景下均可以快速获取到位置结果,我们会把最先拿到的定位结果返回给应用。对设备的硬件资源消耗较大,功耗也较大。 |
437
438
439## LocationError<sup>12+</sup>
440
441持续定位过程中的错误信息。
442
443**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
444
445**系统能力**:SystemCapability.Location.Location.Core
446
447| 名称 | 值 | 说明 |
448| -------- | -------- | -------- |
449| LOCATING_FAILED_DEFAULT   | -1 |  默认值。 |
450| LOCATING_FAILED_LOCATION_PERMISSION_DENIED   | -2 | 表示ohos.permission.APPROXIMATELY_LOCATION权限或ohos.permission.LOCATION权限校验失败导致持续定位失败。 |
451| LOCATING_FAILED_BACKGROUND_PERMISSION_DENIED    | -3 | 表示应用在后台时位置权限校验失败导致持续定位失败。APP在后台定位时的位置权限申请方式参见[申请位置权限开发指导](../../device/location/location-permission-guidelines.md#开发步骤)。 |
452| LOCATING_FAILED_LOCATION_SWITCH_OFF    | -4 | 表示位置信息开关关闭导致持续定位失败。 |
453| LOCATING_FAILED_INTERNET_ACCESS_FAILURE    | -5 | 表示无法访问网络,导致网络定位失败。 |
454
455
456## LocationSourceType<sup>12+</sup>
457
458定位结果的来源。
459
460**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
461
462**系统能力**:SystemCapability.Location.Location.Core
463
464| 名称 | 值 | 说明 |
465| -------- | -------- | -------- |
466| GNSS   | 1 |  表示定位结果来自于GNSS定位技术。 |
467| NETWORK    | 2 | 表示定位结果来自于网络定位技术。 |
468| INDOOR     | 3 | 表示定位结果来自于室内高精度定位技术。 |
469| RTK     | 4 | 表示定位结果来自于室外高精度定位技术。 |
470
471
472## BluetoothScanResult<sup>16+</sup>
473
474蓝牙扫描结果。
475
476**系统能力**:SystemCapability.Location.Location.Core
477
478| 名称 | 类型 | 只读 | 可选 | 说明 |
479| -------- | -------- | -------- | -------- | -------- |
480| deviceId | string | 是 | 否 | 表示扫描到的设备地址。例如:"XX:XX:XX:XX:XX:XX"。 |
481| rssi | number | 是 | 否 | 表示扫描到的设备的rssi值。 |
482| data | ArrayBuffer | 是 | 是 | 表示扫描到的设备发送的广播包。 |
483| deviceName | string | 是 | 否 | 表示扫描到的设备名称。 |
484| connectable | boolean | 是 | 否 | 表示扫描到的设备是否可连接。true表示可连接,false表示不可连接。 |
485
486
487## SportsType<sup>18+</sup>
488
489运动类型。
490
491**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
492
493**系统能力**:SystemCapability.Location.Location.Core
494
495| 名称 | 值 | 说明 |
496| -------- | -------- | -------- |
497| RUNNING   | 1 |  表示跑步。 |
498| WALKING    | 2 | 表示步行。 |
499| CYCLING     | 3 | 表示骑行。 |
500
501
502## geoLocationManager.on('locationChange')
503
504on(type: 'locationChange', request: LocationRequest | ContinuousLocationRequest, callback: Callback&lt;Location&gt;): void
505
506开启位置变化订阅,并发起定位请求。使用callback异步回调。
507
508**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
509
510**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
511
512**系统能力**:SystemCapability.Location.Location.Core
513
514**参数:**
515
516  | 参数名 | 类型 | 必填 | 说明 |
517  | -------- | -------- | -------- | -------- |
518  | type | string | 是 | 设置事件类型。type为“locationChange”,表示位置变化。 |
519  | request |  [LocationRequest](#locationrequest) &#124; [ContinuousLocationRequest](#continuouslocationrequest12) | 是 | 设置位置请求参数。<br/>ContinuousLocationRequest为API12新增参数。 |
520  | callback | Callback&lt;[Location](#location)&gt; | 是 | 回调函数,返回位置信息。 |
521
522**错误码**:
523
524以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
525
526| 错误码ID | 错误信息 |
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**示例**
535
536  ```ts
537  import { geoLocationManager } from '@kit.LocationKit';
538
539  // 方式一:使用LocationRequest作为入参
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  // 方式二:使用ContinuousLocationRequest作为入参
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&lt;Location&gt;): void
566
567关闭位置变化订阅,并删除对应的定位请求。
568
569**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
570
571**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
572
573**系统能力**:SystemCapability.Location.Location.Core
574
575**参数:**
576
577  | 参数名 | 类型 | 必填 | 说明 |
578  | -------- | -------- | -------- | -------- |
579  | type | string | 是 | 设置事件类型。type为“locationChange”,表示位置变化。 |
580  | callback | Callback&lt;[Location](#location)&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
581
582**错误码**:
583
584以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
585
586| 错误码ID | 错误信息 |
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**示例**
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&lt;LocationError&gt;): void
614
615订阅持续定位过程中的错误码。使用callback异步回调。
616
617**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
618
619**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
620
621**系统能力**:SystemCapability.Location.Location.Core
622
623**参数:**
624
625  | 参数名 | 类型 | 必填 | 说明 |
626  | -------- | -------- | -------- | -------- |
627  | type | string | 是 | 设置事件类型。type为“locationError”,表示持续定位过程中的错误码变化。 |
628  | callback | Callback&lt;[LocationError](#locationerror12)&gt; | 是 | 回调函数,返回持续定位过程中的错误码。 |
629
630**错误码**:
631
632以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
633
634| 错误码ID | 错误信息 |
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**示例**
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&lt;LocationError&gt;): void
671
672取消订阅持续定位过程中的错误码。
673
674**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
675
676**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
677
678**系统能力**:SystemCapability.Location.Location.Core
679
680**参数:**
681
682  | 参数名 | 类型 | 必填 | 说明 |
683  | -------- | -------- | -------- | -------- |
684  | type | string | 是 | 设置事件类型。type为“locationError”,表示持续定位过程中的错误码变化。 |
685  | callback | Callback&lt;[LocationError](#locationerror12)&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
686
687**错误码**:
688
689以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
690
691| 错误码ID | 错误信息 |
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**示例**
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&lt;boolean&gt;): void
718
719订阅位置服务状态变化。使用callback异步回调。
720
721**系统能力**:SystemCapability.Location.Location.Core
722
723**参数:**
724
725  | 参数名 | 类型 | 必填 | 说明 |
726  | -------- | -------- | -------- | -------- |
727  | type | string | 是 | 设置事件类型。type为“locationEnabledChange”,表示位置服务状态。 |
728  | callback | Callback&lt;boolean&gt; | 是 | 回调函数。返回true表示位置信息开关已经开启;返回false表示位置信息开关已经关闭。 |
729
730**错误码**:
731
732以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
733
734| 错误码ID | 错误信息 |
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**示例**
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&lt;boolean&gt;): void
759
760取消订阅位置服务状态变化。
761
762**系统能力**:SystemCapability.Location.Location.Core
763
764**参数**:
765
766  | 参数名 | 类型 | 必填 | 说明 |
767  | -------- | -------- | -------- | -------- |
768  | type | string | 是 | 设置事件类型。type为“locationEnabledChange”,表示位置服务状态。 |
769  | callback | Callback&lt;boolean&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
770
771**错误码**:
772
773以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
774
775| 错误码ID | 错误信息 |
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**示例**
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&lt;Array&lt;Location&gt;&gt;): void
801
802订阅缓存GNSS定位结果上报事件。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。使用callback异步回调。
803
804**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
805
806**系统能力**:SystemCapability.Location.Location.Gnss
807
808**参数**:
809
810  | 参数名 | 类型 | 必填 | 说明 |
811  | -------- | -------- | -------- | -------- |
812  | type | string | 是 | 设置事件类型。type为“cachedGnssLocationsChange”,表示GNSS缓存定位结果上报。 |
813  | request |  [CachedGnssLocationsRequest](#cachedgnsslocationsrequest) | 是 | GNSS缓存功能配置参数。 |
814  | callback | Callback&lt;Array&lt;[Location](#location)&gt;&gt; | 是 | 回调函数,返回GNSS缓存位置。 |
815
816**错误码**:
817
818以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
819
820| 错误码ID | 错误信息 |
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**示例**
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&lt;Array&lt;Location&gt;&gt;): void
848
849取消订阅缓存GNSS定位结果上报事件。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。
850
851**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
852
853**系统能力**:SystemCapability.Location.Location.Gnss
854
855**参数**:
856
857  | 参数名 | 类型 | 必填 | 说明 |
858  | -------- | -------- | -------- | -------- |
859  | type | string | 是 | 设置事件类型。type为“cachedGnssLocationsChange”,表示GNSS缓存定位结果上报。 |
860  | callback | Callback&lt;Array&lt;[Location](#location)&gt;&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
861
862**错误码**:
863
864以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
865
866| 错误码ID | 错误信息 |
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**示例**
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&lt;SatelliteStatusInfo&gt;): void
895
896订阅GNSS卫星状态信息上报事件。使用callback异步回调。
897
898**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
899
900**系统能力**:SystemCapability.Location.Location.Gnss
901
902**参数**:
903
904  | 参数名 | 类型 | 必填 | 说明 |
905  | -------- | -------- | -------- | -------- |
906  | type | string | 是 | 设置事件类型。type为“satelliteStatusChange”,表示订阅GNSS卫星状态信息上报。 |
907  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | 是 | 回调函数,返回GNSS卫星状态信息。 |
908
909**错误码**:
910
911以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
912
913| 错误码ID | 错误信息 |
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**示例**
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      // 表示卫星个数
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        // 卫星的ID
939        let satelliteId: Number = satelliteIds[i];
940        // 表示卫星的ID为 ${satelliteId} 的卫星的载波噪声功率谱密度比
941        let carrierToNoiseDensity: Number = carrierToNoiseDensitys[i];
942        // 表示卫星的ID为 ${satelliteId} 的卫星的高度角信息
943        let altitude: Number = altitudes[i];
944        // 表示卫星的ID为 ${satelliteId} 的卫星的方位角
945        let azimuth: Number = azimuths[i];
946        // 表示卫星的ID为 ${satelliteId} 的卫星的载波频率
947        let carrierFrequencie: Number = carrierFrequencies[i];
948        if (satelliteConstellations != undefined) {
949          // 表示卫星的ID为 ${satelliteId} 的卫星的星座类型
950          let satelliteConstellation: geoLocationManager.SatelliteConstellationCategory = satelliteConstellations[i];
951        }
952        if (satelliteAdditionalInfos != undefined) {
953          // 表示卫星的ID为 ${satelliteId} 的卫星的附加信息;表示是否在最新的位置解算中使用了本卫星,是否具有星历数据,是否具有年历数据,是否具有载波频率信息等。
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&lt;SatelliteStatusInfo&gt;): void
970
971取消订阅GNSS卫星状态信息上报事件。
972
973**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
974
975**系统能力**:SystemCapability.Location.Location.Gnss
976
977**参数**:
978
979  | 参数名 | 类型 | 必填 | 说明 |
980  | -------- | -------- | -------- | -------- |
981  | type | string | 是 | 设置事件类型。type为“satelliteStatusChange”,表示订阅GNSS卫星状态信息上报。 |
982  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
983
984**错误码**:
985
986以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
987
988| 错误码ID | 错误信息 |
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**示例**
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&lt;string&gt;): void
1017
1018订阅GNSS NMEA信息上报事件。使用callback异步回调。
1019
1020**需要权限**:ohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
1021
1022**系统能力**:SystemCapability.Location.Location.Gnss
1023
1024**参数**:
1025
1026  | 参数名 | 类型 | 必填 | 说明 |
1027  | -------- | -------- | -------- | -------- |
1028  | type | string | 是 | 设置事件类型。type为“nmeaMessage”,表示订阅GNSS&nbsp;NMEA信息上报。 |
1029  | callback | Callback&lt;string&gt; | 是 | 回调函数,返回GNSS&nbsp;NMEA信息。 |
1030
1031**错误码**:
1032
1033以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1034
1035| 错误码ID | 错误信息 |
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**示例**
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&lt;string&gt;): void
1064
1065取消订阅GNSS NMEA信息上报事件。
1066
1067**需要权限**:ohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
1068
1069**系统能力**:SystemCapability.Location.Location.Gnss
1070
1071**参数**:
1072
1073  | 参数名 | 类型 | 必填 | 说明 |
1074  | -------- | -------- | -------- | -------- |
1075  | type | string | 是 | 设置事件类型。type为“nmeaMessage”,表示订阅GNSS&nbsp;NMEA信息上报。 |
1076  | callback | Callback&lt;string&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
1077
1078**错误码**:
1079
1080以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1081
1082| 错误码ID | 错误信息 |
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**示例**
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
1113添加一个围栏,并订阅地理围栏事件。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。
1114
1115**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1116
1117**系统能力**:SystemCapability.Location.Location.Geofence
1118
1119**参数**:
1120
1121  | 参数名 | 类型 | 必填 | 说明 |
1122  | -------- | -------- | -------- | -------- |
1123  | type | string | 是 | 设置事件类型。type为“gnssFenceStatusChange”,表示订阅围栏事件上报。 |
1124  | request |  [GeofenceRequest](#geofencerequest) | 是 | 围栏的配置参数。 |
1125  | want | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | 是 | 用于接收地理围栏事件上报(进出围栏)。 |
1126
1127**错误码**:
1128
1129以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1130
1131| 错误码ID | 错误信息 |
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**示例**
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
1175删除一个围栏,并取消订阅该围栏事件。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。
1176
1177**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1178
1179**系统能力**:SystemCapability.Location.Location.Geofence
1180
1181**参数**:
1182
1183  | 参数名 | 类型 | 必填 | 说明 |
1184  | -------- | -------- | -------- | -------- |
1185  | type | string | 是 | 设置事件类型。type为“gnssFenceStatusChange”,表示订阅围栏事件上报。 |
1186  | request | [GeofenceRequest](#geofencerequest) | 是 | 围栏的配置参数。 |
1187  | want | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | 是 | 用于接收地理围栏事件上报(进出围栏)。 |
1188
1189**错误码**:
1190
1191以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1192
1193| 错误码ID | 错误信息 |
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**示例**
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&lt;CountryCode&gt;): void
1237
1238订阅国家码信息变化事件。使用callback异步回调。
1239
1240**系统能力**:SystemCapability.Location.Location.Core
1241
1242**参数**:
1243
1244  | 参数名 | 类型 | 必填 | 说明 |
1245  | -------- | -------- | -------- | -------- |
1246  | type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示订阅国家码信息变化事件。 |
1247  | callback | Callback&lt;[CountryCode](#countrycode)&gt; | 是 | 回调函数,返回国家码信息。 |
1248
1249**错误码**:
1250
1251以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1252
1253| 错误码ID | 错误信息 |
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**示例**
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&lt;CountryCode&gt;): void
1281
1282取消订阅国家码变化事件。
1283
1284**系统能力**:SystemCapability.Location.Location.Core
1285
1286**参数**:
1287
1288  | 参数名 | 类型 | 必填 | 说明 |
1289  | -------- | -------- | -------- | -------- |
1290  | type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示取消订阅国家码信息变化事件。 |
1291  | callback | Callback&lt;[CountryCode](#countrycode)&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
1292
1293**错误码**:
1294
1295以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1296
1297| 错误码ID | 错误信息 |
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**示例**
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&lt;Location&gt;): void
1325
1326获取当前位置,使用callback异步回调。
1327
1328**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1329
1330**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1331
1332**系统能力**:SystemCapability.Location.Location.Core
1333
1334**参数**:
1335
1336  | 参数名 | 类型 | 必填 | 说明 |
1337  | -------- | -------- | -------- | -------- |
1338  | request | [CurrentLocationRequest](#currentlocationrequest) &#124;  [SingleLocationRequest](#singlelocationrequest12) | 是 | 设置位置请求参数。<br/>SingleLocationRequest为API12新增参数。 |
1339  | callback | AsyncCallback&lt;[Location](#location)&gt; | 是 | 回调函数,返回当前位置信息。 |
1340
1341**错误码**:
1342
1343以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1344
1345| 错误码ID | 错误信息 |
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**示例**
1355
1356  ```ts
1357  import { geoLocationManager } from '@kit.LocationKit';
1358  import { BusinessError } from '@kit.BasicServicesKit';
1359  // 方式一:使用CurrentLocationRequest作为入参
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  // 方式二:使用SingleLocationRequest作为入参
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&lt;Location&gt;): void
1397
1398获取当前位置,使用callback异步回调。
1399
1400**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1401
1402**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1403
1404**系统能力**:SystemCapability.Location.Location.Core
1405
1406**参数**:
1407
1408  | 参数名 | 类型 | 必填 | 说明 |
1409  | -------- | -------- | -------- | -------- |
1410  | callback | AsyncCallback&lt;[Location](#location)&gt; | 是 | 回调函数,返回当前位置信息。 |
1411
1412**错误码**:
1413
1414以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1415
1416| 错误码ID | 错误信息 |
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**示例**
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&lt;Location&gt;
1449
1450获取当前位置,使用Promise异步回调。
1451
1452**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1453
1454**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1455
1456**系统能力**:SystemCapability.Location.Location.Core
1457
1458**参数**:
1459
1460  | 参数名 | 类型 | 必填 | 说明 |
1461  | -------- | -------- | -------- | -------- |
1462  | request | [CurrentLocationRequest](#currentlocationrequest) &#124; [SingleLocationRequest](#singlelocationrequest12) | 否 | 设置位置请求参数。<br/>SingleLocationRequest为API12新增参数。 |
1463
1464**返回值**:
1465
1466  | 类型 | 说明 |
1467  | -------- | -------- |
1468  | Promise&lt;[Location](#location)&gt; | Promise对象,返回当前位置信息。 |
1469
1470**错误码**:
1471
1472以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1473
1474| 错误码ID | 错误信息 |
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**示例**
1484
1485  ```ts
1486  import { geoLocationManager } from '@kit.LocationKit';
1487  import { BusinessError } from '@kit.BasicServicesKit';
1488
1489  // 方式一:使用CurrentLocationRequest作为入参
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  // 方式二:使用SingleLocationRequest作为入参
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
1521获取上一次位置。
1522
1523**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1524
1525**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1526
1527**系统能力**:SystemCapability.Location.Location.Core
1528
1529**返回值**:
1530
1531  | 类型 | 说明 |
1532  | -------- | -------- |
1533  | [Location](#location) | 位置信息。 |
1534
1535**错误码**:
1536
1537以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1538
1539| 错误码ID | 错误信息 |
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**示例**
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
1563判断位置服务是否已经开启。
1564
1565**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1566
1567**系统能力**:SystemCapability.Location.Location.Core
1568
1569**返回值**:
1570
1571  | 类型 | 说明 |
1572  | -------- | -------- |
1573  | boolean | true:位置信息开关已开启。<br/>false:位置信息开关已关闭。 |
1574
1575**错误码**:
1576
1577以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1578
1579| 错误码ID | 错误信息 |
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**示例**
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&lt;Array&lt;GeoAddress&gt;&gt;): void
1599
1600调用逆地理编码服务,将坐标转换为地理描述,使用callback异步回调。
1601
1602**系统能力**:SystemCapability.Location.Location.Geocoder
1603
1604**参数**:
1605
1606  | 参数名 | 类型 | 必填 | 说明 |
1607  | -------- | -------- | -------- | -------- |
1608  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 设置逆地理编码请求的相关参数。 |
1609  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 是 | 回调函数,返回逆地理编码结果。 |
1610
1611**错误码**:
1612
1613以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1614
1615| 错误码ID | 错误信息 |
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**示例**
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&lt;Array&lt;GeoAddress&gt;&gt;
1645
1646调用逆地理编码服务,将坐标转换为地理描述,使用Promise异步回调。
1647
1648**系统能力**:SystemCapability.Location.Location.Geocoder
1649
1650**参数**:
1651
1652  | 参数名 | 类型 | 必填 | 说明 |
1653  | -------- | -------- | -------- | -------- |
1654  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 设置逆地理编码请求的相关参数。 |
1655
1656**返回值**:
1657
1658  | 类型 | 说明 |
1659  | -------- | -------- |
1660  | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Promise对象,返回地理描述信息。 |
1661
1662**错误码**:
1663
1664以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1665
1666| 错误码ID | 错误信息 |
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**示例**
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&lt;Array&lt;GeoAddress&gt;&gt;): void
1695
1696调用地理编码服务,将地理描述转换为具体坐标,使用callback异步回调。
1697
1698**系统能力**:SystemCapability.Location.Location.Geocoder
1699
1700**参数**:
1701
1702  | 参数名 | 类型 | 必填 | 说明 |
1703  | -------- | -------- | -------- | -------- |
1704  | request | [GeoCodeRequest](#geocoderequest) | 是 | 设置地理编码请求的相关参数。 |
1705  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 是 | 回调函数,返回地理编码结果。 |
1706
1707**错误码**:
1708
1709以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1710
1711| 错误码ID | 错误信息 |
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**示例**
1719
1720  ```ts
1721  import { geoLocationManager } from '@kit.LocationKit';
1722  let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "上海市浦东新区xx路xx号", "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&lt;Array&lt;GeoAddress&gt;&gt;
1741
1742调用地理编码服务,将地理描述转换为具体坐标,使用Promise异步回调。
1743
1744**系统能力**:SystemCapability.Location.Location.Geocoder
1745
1746**参数**:
1747
1748  | 参数名 | 类型 | 必填 | 说明 |
1749  | -------- | -------- | -------- | -------- |
1750  | request | [GeoCodeRequest](#geocoderequest) | 是 | 设置地理编码请求的相关参数。 |
1751
1752**返回值**:
1753
1754  | 类型 | 说明 |
1755  | -------- | -------- |
1756  | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Promise对象,返回地理编码查询结果。 |
1757
1758**错误码**:
1759
1760以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1761
1762| 错误码ID | 错误信息 |
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**示例**
1770
1771  ```ts
1772  import { geoLocationManager } from '@kit.LocationKit';
1773  import { BusinessError } from '@kit.BasicServicesKit';
1774  let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "上海市浦东新区xx路xx号", "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
1791判断地理编码与逆地理编码服务状态。
1792
1793**系统能力**:SystemCapability.Location.Location.Geocoder
1794
1795**返回值**:
1796
1797  | 类型 | 说明 |
1798  | -------- | -------- |
1799  | boolean | true:地理编码与逆地理编码服务可用。<br/>false:地理编码与逆地理编码服务不可用。 |
1800
1801**错误码**:
1802
1803以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1804
1805| 错误码ID | 错误信息 |
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**示例**
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&lt;number&gt;): void
1825
1826获取GNSS芯片缓存位置的个数。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。使用callback异步回调。
1827
1828**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1829
1830**系统能力**:SystemCapability.Location.Location.Gnss
1831
1832**参数**:
1833
1834  | 参数名 | 类型 | 必填 | 说明 |
1835  | -------- | -------- | -------- | -------- |
1836  | callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回GNSS芯片缓存位置个数。 |
1837
1838**错误码**:
1839
1840以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1841
1842| 错误码ID | 错误信息 |
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**示例**
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&lt;number&gt;
1872
1873获取GNSS芯片缓存位置的个数。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。使用Promise异步回调。
1874
1875**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1876
1877**系统能力**:SystemCapability.Location.Location.Gnss
1878
1879**返回值**:
1880
1881  | 类型 | 说明 |
1882  | -------- | -------- |
1883  | Promise&lt;number&gt; | Promise对象,返回GNSS缓存位置的个数。 |
1884
1885**错误码**:
1886
1887以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1888
1889| 错误码ID | 错误信息 |
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**示例**
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&lt;void&gt;): void
1917
1918读取并清空GNSS芯片所有缓存位置。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。使用callback异步回调。
1919
1920**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1921
1922**系统能力**:SystemCapability.Location.Location.Gnss
1923
1924**参数**:
1925
1926  | 参数名 | 类型 | 必填 | 说明 |
1927  | -------- | -------- | -------- | -------- |
1928  | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当操作成功,err为undefined,否则为错误对象。 |
1929
1930**错误码**:
1931
1932以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1933
1934| 错误码ID | 错误信息 |
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**示例**
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&lt;void&gt;
1962
1963读取并清空GNSS芯片所有缓存位置。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。使用Promise异步回调。
1964
1965**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1966
1967**系统能力**:SystemCapability.Location.Location.Gnss
1968
1969**返回值**:
1970
1971  | 类型 | 说明 |
1972  | -------- | -------- |
1973  | Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象 |
1974
1975**错误码**:
1976
1977以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1978
1979| 错误码ID | 错误信息 |
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**示例**
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&lt;void&gt;): void
2008
2009给位置服务子系统的各个部件发送扩展命令。使用callback异步回调。
2010
2011**系统能力**:SystemCapability.Location.Location.Core
2012
2013**参数**:
2014
2015  | 参数名 | 类型 | 必填 | 说明 |
2016  | -------- | -------- | -------- | -------- |
2017  | command |  [LocationCommand](#locationcommand) | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
2018  | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当命令发送成功,err为undefined,否则为错误对象。 |
2019
2020**错误码**:
2021
2022以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2023
2024| 错误码ID | 错误信息 |
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**示例**
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&lt;void&gt;
2050
2051给位置服务子系统的各个部件发送扩展命令。使用Promise异步回调。
2052
2053**系统能力**:SystemCapability.Location.Location.Core
2054
2055**参数**:
2056
2057  | 参数名 | 类型 | 必填 | 说明 |
2058  | -------- | -------- | -------- | -------- |
2059  | command | [LocationCommand](#locationcommand) | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
2060
2061**返回值**:
2062
2063  | 类型 | 说明 |
2064  | -------- | -------- |
2065  | Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象 |
2066
2067**错误码**:
2068
2069以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2070
2071| 错误码ID | 错误信息 |
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**示例**
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&lt;CountryCode&gt;): void
2099
2100查询当前的国家码。使用callback异步回调。
2101
2102**系统能力**:SystemCapability.Location.Location.Core
2103
2104**参数**:
2105
2106  | 参数名 | 类型 | 必填 | 说明 |
2107  | -------- | -------- | -------- | -------- |
2108  | callback | AsyncCallback&lt;[CountryCode](#countrycode)&gt; | 是 | 回调函数,返回国家码信息。 |
2109
2110**错误码**:
2111
2112以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2113
2114| 错误码ID | 错误信息 |
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**示例**
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&lt;CountryCode&gt;
2143
2144查询当前的国家码。使用Promise异步回调。
2145
2146**系统能力**:SystemCapability.Location.Location.Core
2147
2148**返回值**:
2149
2150  | 类型 | 说明 |
2151  | -------- | -------- |
2152  | Promise&lt;[CountryCode](#countrycode)&gt; | Promise对象,返回国家码信息。 |
2153
2154**错误码**:
2155
2156以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2157
2158| 错误码ID | 错误信息 |
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**示例**
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&lt;number&gt;
2185
2186添加一个GNSS地理围栏,并订阅地理围栏事件。使用Promise异步回调。
2187
2188APP可以在入参[GnssGeofenceRequest](#gnssgeofencerequest12)中传入回调函数用于接收地理围栏事件;也可以传入通知对象[NotificationRequest](../apis-notification-kit/js-apis-notification.md#notificationrequest),在系统识别到地理围栏事件发生时会弹出APP创建的通知。
2189
2190GNSS地理围栏功能依赖GNSS定位芯片(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。
2191
2192**需要权限**:ohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
2193
2194**系统能力**:SystemCapability.Location.Location.Geofence
2195
2196**参数**:
2197
2198  | 参数名 | 类型 | 必填 | 说明 |
2199  | -------- | -------- | -------- | -------- |
2200  | fenceRequest | [GnssGeofenceRequest](#gnssgeofencerequest12) | 是 | 添加GNSS地理围栏请求参数。<br/>包含圆形围栏信息、需要监听的地理围栏事件、地理围栏事件触发后弹出的通知对象和监听地理围栏事件的回调函数。 |
2201
2202**返回值**:
2203
2204  | 类型 | 说明 |
2205  | -------- | -------- |
2206  | Promise&lt;number&gt; | Promise对象,返回地理围栏ID。 |
2207
2208**错误码**:
2209
2210以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2211
2212| 错误码ID | 错误信息 |
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**示例**
2222
2223  ```ts
2224  import { geoLocationManager } from '@kit.LocationKit';
2225  import { BusinessError } from '@kit.BasicServicesKit';
2226  import { notificationManager } from '@kit.NotificationKit';
2227  // 创建围栏
2228  let geofence: geoLocationManager.Geofence = {
2229    "latitude": 34.12, "longitude": 124.11, "radius": 10000.0, "expiration": 10000.0
2230  }
2231  // 指定APP需要监听的地理围栏事件类型,这里表示需要监听进入围栏和退出围栏事件
2232  let transitionStatusList: Array<geoLocationManager.GeofenceTransitionEvent> = [
2233    geoLocationManager.GeofenceTransitionEvent.GEOFENCE_TRANSITION_EVENT_ENTER,
2234    geoLocationManager.GeofenceTransitionEvent.GEOFENCE_TRANSITION_EVENT_EXIT,
2235  ];
2236  // 创建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: "围栏通知",
2243        text: "围栏进入",
2244        additionalText: ""
2245      }
2246    }
2247  };
2248  // 创建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: '围栏通知',
2255        text: '围栏退出',
2256        additionalText: ""
2257      }
2258    }
2259  };
2260  // 把创建的通知对象存入Array中,存入顺序与transitionStatusList一致
2261  let notificationRequestList: Array<notificationManager.NotificationRequest> =
2262    [notificationRequest1, notificationRequest2];
2263  // 构造GNSS地理围栏请求对象gnssGeofenceRequest
2264  let gnssGeofenceRequest: geoLocationManager.GnssGeofenceRequest = {
2265    // 围栏属性,包含圆心和半径等信息
2266    geofence: geofence,
2267    // 指定APP需要监听的地理围栏事件类型
2268    monitorTransitionEvents: transitionStatusList,
2269    // 地理围栏事件对应的通知对象,该参数为可选
2270    notifications: notificationRequestList,
2271    // 用于监听围栏事件的callback
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    // 添加围栏
2283    geoLocationManager.addGnssGeofence(gnssGeofenceRequest).then((id) => {
2284      // 围栏添加成功后返回围栏ID
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&lt;void&gt;
2300
2301删除一个GNSS地理围栏,并取消订阅该地理围栏事件。使用Promise异步回调。
2302
2303GNSS地理围栏功能依赖GNSS定位芯片(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。
2304
2305**需要权限**:ohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
2306
2307**系统能力**:SystemCapability.Location.Location.Geofence
2308
2309**参数**:
2310
2311  | 参数名 | 类型 | 必填 | 说明 |
2312  | -------- | -------- | -------- | -------- |
2313  | geofenceId | number | 是 | GNSS地理围栏的ID。 |
2314
2315**返回值**:
2316
2317  | 类型 | 说明 |
2318  | -------- | -------- |
2319  | Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
2320
2321**错误码**:
2322
2323以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2324
2325| 错误码ID | 错误信息 |
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**示例**
2334
2335  ```ts
2336  import { geoLocationManager } from '@kit.LocationKit';
2337  import { BusinessError } from '@kit.BasicServicesKit';
2338  // fenceId是在geoLocationManager.addGnssGeofence执行成功后获取的
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&lt;CoordinateSystemType&gt;
2355
2356获取地理围栏功能支持的坐标系列表。
2357
2358**系统能力**:SystemCapability.Location.Location.Geofence
2359
2360**返回值**:
2361
2362  | 类型 | 说明 |
2363  | -------- | -------- |
2364  | Array&lt;[CoordinateSystemType](#coordinatesystemtype12)&gt; | 地理围栏功能支持的坐标系列表。 |
2365
2366**错误码**:
2367
2368以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2369
2370| 错误码ID | 错误信息 |
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**示例**
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
2392获取连接的Wi-Fi AP(Access Point)的Bssid(Basic Service Set Identifier)信息
2393
2394**需要权限**:ohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
2395
2396**系统能力**:SystemCapability.Location.Location.Core
2397
2398**返回值**:
2399
2400  | 类型 | 说明 |
2401  | -------- | -------- |
2402  | string | Wi-Fi Bssid |
2403
2404**错误码**:
2405
2406以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2407
2408| 错误码ID | 错误信息 |
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**示例**
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&lt;BluetoothScanResult&gt;): void
2432
2433订阅蓝牙扫描信息上报事件,使用callback异步回调。
2434
2435<!--RP1--><!--RP1End-->
2436
2437本API会启动蓝牙扫描,为了避免产生较多功耗,需要开发者在适当的时机调用 [geoLocationManager.off('bluetoothScanResultChange')](#geolocationmanageroffbluetoothscanresultchange16)接口停止蓝牙扫描。
2438
2439当前仅支持扫描BLE设备。
2440
2441**需要权限**:ohos.permission.APPROXIMATELY_LOCATIONohos.permission.LOCATION
2442
2443**系统能力**:SystemCapability.Location.Location.Core
2444
2445**参数**:
2446
2447  | 参数名 | 类型 | 必填 | 说明 |
2448  | -------- | -------- | -------- | -------- |
2449  | type | string | 是 | 设置事件类型。type为“bluetoothScanResultChange”,表示订阅蓝牙扫描信息上报事件。 |
2450  | callback | Callback&lt;[BluetoothScanResult](#bluetoothscanresult16)&gt; | 是 | 回调函数,返回蓝牙扫描信息。 |
2451
2452**错误码**:
2453
2454以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2455
2456| 错误码ID | 错误信息 |
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**示例**
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&lt;BluetoothScanResult&gt;): void
2485
2486取消订阅蓝牙扫描信息上报事件并停止蓝牙扫描。
2487
2488**需要权限**:ohos.permission.APPROXIMATELY_LOCATIONohos.permission.LOCATION
2489
2490**系统能力**:SystemCapability.Location.Location.Core
2491
2492**参数**:
2493
2494  | 参数名 | 类型 | 必填 | 说明 |
2495  | -------- | -------- | -------- | -------- |
2496  | type | string | 是 | 设置事件类型。type为“bluetoothScanResultChange”,表示停止订阅蓝牙扫描信息上报事件。 |
2497  | callback | Callback&lt;[BluetoothScanResult](#bluetoothscanresult16)&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
2498
2499**错误码**:
2500
2501以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2502
2503| 错误码ID | 错误信息 |
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**示例**
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  ```