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
131
132## SingleLocationRequest<sup>12+</sup>
133
134单次定位的请求参数。
135
136**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
137
138**系统能力**:SystemCapability.Location.Location.Core
139
140| 名称 | 类型 | 只读 | 可选 | 说明 |
141| -------- | -------- | -------- | -------- | -------- |
142| locatingPriority | [LocatingPriority](#locatingpriority12) | 否 | 否 | 表示优先级信息。取值范围见[LocatingPriority](#locatingpriority12)的定义。|
143| locatingTimeoutMs | number | 否 | 否 | 表示超时时间,单位是毫秒,最小为1000毫秒。取值范围为大于等于1000。 |
144
145
146## SatelliteStatusInfo
147
148卫星状态信息。
149
150**系统能力**:SystemCapability.Location.Location.Gnss
151
152| 名称 | 类型 | 只读 | 可选 | 说明 |
153| -------- | -------- | -------- | -------- | -------- |
154| satellitesNumber | number | 否 | 否 | 表示卫星个数。取值范围为大于等于0。 |
155| satelliteIds | Array&lt;number&gt; | 否 | 否 | 表示每个卫星的ID,数组类型。取值范围为大于等于0。 |
156| carrierToNoiseDensitys | Array&lt;number&gt; | 否 | 否 | 表示载波噪声功率谱密度比,即cn0。取值范围为大于0。 |
157| altitudes | Array&lt;number&gt; | 否 | 否 | 表示卫星高度角信息。单位是“度”,取值范围为-90到90。 |
158| azimuths | Array&lt;number&gt; | 否 | 否 | 表示方位角。单位是“度”,取值范围为0到360。 |
159| carrierFrequencies | Array&lt;number&gt; | 否 | 否 | 表示载波频率。单位是Hz,取值范围为大于等于0。 |
160| satelliteConstellation<sup>12+</sup> | Array&lt;[SatelliteConstellationCategory](#satelliteconstellationcategory12)&gt; | 否 | 是 | 表示卫星星座类型。 |
161| satelliteAdditionalInfo<sup>12+</sup> | Array&lt;number&gt; | 否 | 是 | 表示卫星的附加信息。<br/>每个比特位代表不同含义,具体定义参见[SatelliteAdditionalInfo](#satelliteadditionalinfo12)。 |
162
163
164## CachedGnssLocationsRequest
165
166请求订阅GNSS缓存位置上报功能接口的配置参数。
167
168**系统能力**:SystemCapability.Location.Location.Gnss
169
170| 名称 | 类型 | 只读 | 可选 | 说明 |
171| -------- | -------- | -------- | -------- | -------- |
172| reportingPeriodSec | number | 否 | 否 | 表示GNSS缓存位置上报的周期,单位是毫秒。取值范围为大于0。 |
173| wakeUpCacheQueueFull | boolean | 否 | 否  | true表示GNSS芯片底层缓存队列满之后会主动唤醒AP芯片,并把缓存位置上报给应用。<br/>false表示GNSS芯片底层缓存队列满之后不会主动唤醒AP芯片,会把缓存位置直接丢弃。 |
174
175
176## Geofence
177
178GNSS围栏的配置参数。目前只支持圆形围栏。
179
180**系统能力**:SystemCapability.Location.Location.Geofence
181
182| 名称 | 类型 | 只读 | 可选 | 说明 |
183| -------- | -------- | -------- | -------- | -------- |
184| latitude | number | 否 | 否 |表示纬度。取值范围为-90到90。 |
185| longitude | number | 否 |否 | 表示经度。取值范围为-180到180。 |
186| coordinateSystemType<sup>12+</sup> | [CoordinateSystemType](#coordinatesystemtype12) | 否 |是 | 表示地理围栏圆心坐标的坐标系。<br/>APP应先使用[getGeofenceSupportedCoordTypes](#geolocationmanagergetgeofencesupportedcoordtypes12)查询支持的坐标系,然后传入正确的圆心坐标。 |
187| radius | number | 否 |否 | 表示圆形围栏的半径。单位是米,取值范围为大于0。 |
188| expiration | number | 否 |否 | 围栏存活的时间,单位是毫秒。取值范围为大于0。 |
189
190
191## GeofenceRequest
192
193请求添加GNSS围栏消息中携带的参数,包括定位场景和围栏信息。
194
195**系统能力**:SystemCapability.Location.Location.Geofence
196
197| 名称 | 类型 | 只读 | 可选 | 说明 |
198| -------- | -------- | -------- | -------- | -------- |
199| scenario | [LocationRequestScenario](#locationrequestscenario) | 否 | 否  |  表示定位场景。 |
200| geofence |  [Geofence](#geofence)| 否 | 否  |  表示围栏信息。 |
201
202
203## LocationCommand
204
205扩展命令参数。
206
207**系统能力**:SystemCapability.Location.Location.Core
208
209| 名称 | 类型 | 只读 | 可选 | 说明 |
210| -------- | -------- | -------- | -------- | -------- |
211| scenario | [LocationRequestScenario](#locationrequestscenario)  | 否 | 否  | 表示定位场景。 |
212| command | string | 否 | 否  | 扩展命令字符串。 |
213
214
215## Location
216
217位置信息。
218
219**系统能力**:SystemCapability.Location.Location.Core
220
221| 名称 | 类型 | 只读 | 可选 | 说明 |
222| -------- | -------- | -------- | -------- | -------- |
223| latitude | number| 否 | 否 | 表示纬度信息,正值表示北纬,负值表示南纬。取值范围为-90到90。仅支持WGS84坐标系。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
224| longitude | number| 否 | 否 | 表示经度信息,正值表示东经,负值表是西经。取值范围为-180到180。仅支持WGS84坐标系。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
225| altitude | number | 否 | 否 | 表示高度信息,单位米。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
226| accuracy | number | 否 | 否 | 表示精度信息,单位米。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
227| speed | number | 否 | 否 |表示速度信息,单位米每秒。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
228| timeStamp | number | 否 | 否 | 表示位置时间戳,UTC格式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
229| direction | number | 否 | 否 | 表示航向信息。单位是“度”,取值范围为0到360。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
230| timeSinceBoot | number | 否 | 否 | 表示位置时间戳,开机时间格式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
231| additions | Array&lt;string&gt;| 否 | 是 | 附加信息。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
232| additionSize | number| 否 | 是 | 附加信息数量。取值范围为大于等于0。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
233| additionsMap<sup>12+</sup> | Map&lt;string, string&gt;| 否 | 是 | 附加信息。具体内容和顺序与additions一致。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
234| altitudeAccuracy<sup>12+</sup> |number | 否 | 是 | 表示高度信息的精度,单位米。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
235| speedAccuracy<sup>12+</sup> | number| 否 | 是 | 表示速度信息的精度,单位米每秒。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
236| directionAccuracy<sup>12+</sup> | number| 否 | 是 | 表示航向信息的精度。单位是“度”,取值范围为0到360。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
237| uncertaintyOfTimeSinceBoot<sup>12+</sup> | number| 否 | 是 | 表示位置时间戳的不确定度。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
238| sourceType<sup>12+</sup> | [LocationSourceType](#locationsourcetype12) | 否 | 是 | 表示定位结果的来源。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
239
240
241## GeofenceTransition<sup>12+</sup>
242
243地理围栏事件信息;包含地理围栏ID和具体的地理围栏事件。
244
245**系统能力**:SystemCapability.Location.Location.Geofence
246
247| 名称 | 类型 | 只读 | 可选 | 说明 |
248| -------- | -------- | -------- | -------- | -------- |
249| geofenceId | number| 否 | 否 | 表示地理围栏ID。 |
250| transitionEvent | [GeofenceTransitionEvent](#geofencetransitionevent12) | 否 | 否 | 表示当前发生的地理围栏事件。 |
251
252
253## GnssGeofenceRequest<sup>12+</sup>
254
255GNSS地理围栏请求参数。
256
257**系统能力**:SystemCapability.Location.Location.Geofence
258
259| 名称 | 类型 | 只读 | 可选 | 说明 |
260| -------- | -------- | -------- | -------- | -------- |
261| geofence | [Geofence](#geofence) | 否 | 否 | 表示地理围栏信息,包含圆形围栏圆心坐标、半径等信息。 |
262| monitorTransitionEvents | Array&lt;[GeofenceTransitionEvent](#geofencetransitionevent12)&gt; | 否 | 否 | 表示APP监听的地理围栏事件列表。 |
263| 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]中就需要填入用户进入围栏时需要弹出的通知对象。 |
264| geofenceTransitionCallback | AsyncCallback&lt;[GeofenceTransition](#geofencetransition12)&gt; | 否 | 否 | 表示用于接收地理围栏事件的回调函数。 |
265
266
267## CountryCode
268
269国家码信息,包含国家码字符串和国家码的来源信息。
270
271**系统能力**:SystemCapability.Location.Location.Core
272
273| 名称 | 类型 | 只读 | 可选 | 说明 |
274| -------- | -------- | -------- | -------- | -------- |
275| country | string | 否 | 否 | 表示国家码字符串。 |
276| type |  [CountryCodeType](#countrycodetype) | 否 | 否 | 表示国家码信息来源。 |
277
278
279## LocationRequestPriority
280
281位置请求中位置信息优先级类型。
282
283**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
284
285**系统能力**:SystemCapability.Location.Location.Core
286
287| 名称 | 值 | 说明 |
288| -------- | -------- | -------- |
289| UNSET | 0x200 | 表示未设置优先级,表示[LocationRequestPriority](#locationrequestpriority)无效。 |
290| ACCURACY | 0x201 | 表示精度优先。<br/>定位精度优先策略主要以GNSS定位技术为主。我们会在GNSS提供稳定位置结果之前使用网络定位技术提供服务。在持续定位过程中,如果超过30秒无法获取GNSS定位结果则使用网络定位技术。对设备的硬件资源消耗较大,功耗较大。 |
291| LOW_POWER | 0x202 | 表示低功耗优先。<br/>低功耗定位优先策略仅使用网络定位技术,在室内和户外场景均可提供定位服务,因为其依赖周边基站、可见WLAN、蓝牙设备的分布情况,定位结果的精度波动范围较大,推荐在对定位结果精度要求不高的场景下使用该策略,可以有效节省设备功耗。 |
292| FIRST_FIX | 0x203 | 表示快速获取位置优先,如果应用希望快速拿到一个位置,可以将优先级设置为该字段。<br/>快速定位优先策略会同时使用GNSS定位和网络定位技术,以便在室内和户外场景下均可以快速获取到位置结果;当各种定位技术都有提供位置结果时,系统会选择其中精度较好的结果返回给应用。因为对各种定位技术同时使用,对设备的硬件资源消耗较大,功耗也较大。 |
293
294
295## LocationRequestScenario
296
297位置请求中定位场景类型。
298
299**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
300
301**系统能力**:SystemCapability.Location.Location.Core
302
303> **说明:**
304>
305> 当使用NAVIGATION/TRAJECTORY_TRACKING/CAR_HAILING场景进行单次定位或持续定位时,我们会在GNSS提供稳定位置结果之前使用网络定位技术提供服务;在持续定位时,如果超过30秒无法获取GNSS定位结果则会使用网络定位技术获取位置。
306
307| 名称 | 值 | 说明 |
308| -------- | -------- | -------- |
309| UNSET | 0x300 | 表示未设置场景信息。<br/>表示[LocationRequestScenario](#locationrequestscenario)字段无效。 |
310| NAVIGATION | 0x301 | 表示导航场景。<br/>适用于在户外获取设备实时位置的场景,如车载、步行导航。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。 |
311| TRAJECTORY_TRACKING | 0x302 | 表示运动轨迹记录场景。<br/>适用于记录用户位置轨迹的场景,如运动类应用记录轨迹功能。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。 |
312| CAR_HAILING | 0x303 | 表示打车场景。<br/>适用于用户出行打车时定位当前位置的场景,如网约车类应用。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。 |
313| DAILY_LIFE_SERVICE | 0x304 | 表示日常服务使用场景。<br/>适用于不需要定位用户精确位置的使用场景,如新闻资讯、网购、点餐类应用。<br/>该场景仅使用网络定位技术提供定位服务,功耗较低。 |
314| NO_POWER | 0x305 | 表示无功耗功场景,这种场景下不会主动触发定位,会在其他应用定位时,才给当前应用返回位置。 |
315
316
317## CountryCodeType
318
319国家码来源类型。
320
321**系统能力**:SystemCapability.Location.Location.Core
322
323| 名称 | 值 | 说明 |
324| -------- | -------- | -------- |
325| COUNTRY_CODE_FROM_LOCALE | 1 | 从全球化模块的语言配置信息中获取到的国家码。 |
326| COUNTRY_CODE_FROM_SIM | 2 | 从SIM卡中获取到的国家码。 |
327| COUNTRY_CODE_FROM_LOCATION | 3 | 基于用户的位置信息,通过逆地理编码查询到的国家码。 |
328| COUNTRY_CODE_FROM_NETWORK | 4 | 从蜂窝网络注册信息中获取到的国家码。 |
329
330
331## CoordinateSystemType<sup>12+</sup>
332
333坐标系类型。
334
335**系统能力**:SystemCapability.Location.Location.Geofence
336
337| 名称 | 值 | 说明 |
338| -------- | -------- | -------- |
339| WGS84 | 1 | World Geodetic System 1984,是为GPS全球定位系统使用而建立的坐标系统。 |
340| GCJ02 | 2 | GCJ-02是由中国国家测绘局制订的地理信息系统的坐标系统。 |
341
342
343## GeofenceTransitionEvent<sup>12+</sup>
344
345地理围栏事件。
346
347**系统能力**:SystemCapability.Location.Location.Geofence
348
349| 名称 | 值 | 说明 |
350| -------- | -------- | -------- |
351| GEOFENCE_TRANSITION_EVENT_ENTER  | 1 | 该事件表示设备从地理围栏外进入地理围栏内。 |
352| GEOFENCE_TRANSITION_EVENT_EXIT  | 2 | 该事件表示设备从地理围栏内退出到地理围栏外。 |
353| GEOFENCE_TRANSITION_EVENT_DWELL   | 4 | 该事件表示设备在地理围栏范围内,且持续徘徊超过10秒。 |
354
355
356## SatelliteConstellationCategory<sup>12+</sup>
357
358卫星星座类型。
359
360**系统能力**:SystemCapability.Location.Location.Gnss
361
362| 名称 | 值 | 说明 |
363| -------- | -------- | -------- |
364| CONSTELLATION_CATEGORY_UNKNOWN   | 0 | 默认值。 |
365| CONSTELLATION_CATEGORY_GPS   | 1 | GPS(Global Positioning System),即全球定位系统,是美国研制发射的一种以人造地球卫星为基础的高精度无线电导航的定位系统。 |
366| CONSTELLATION_CATEGORY_SBAS    | 2 | SBAS(Satellite-Based Augmentation System),即星基增强系统,通过地球静止轨道(GEO)卫星搭载卫星导航增强信号转发器,可以向用户播发星历误差、卫星钟差、电离层延迟等多种修正信息,实现对于原有卫星导航系统定位精度的改进。 |
367| CONSTELLATION_CATEGORY_GLONASS    | 3 | GLONASS(GLOBAL NAVIGATION SATELLITE SYSTEM),是苏联/俄罗斯研制卫星导航系统。 |
368| CONSTELLATION_CATEGORY_QZSS    | 4 | QZSS(Quasi-Zenith Satellite System),即准天顶卫星系统,是以三颗人造卫星透过时间转移完成全球定位系统区域性功能的卫星扩增系统,是日本研发的卫星系统。 |
369| CONSTELLATION_CATEGORY_BEIDOU     | 5 | 北斗卫星导航系统(Beidou Navigation Satellite System)是中国自行研制的全球卫星导航系统。 |
370| CONSTELLATION_CATEGORY_GALILEO     | 6 | GALILEO(Galileo satellite navigation system),即伽利略卫星导航系统,是由欧盟研制和建立的全球卫星导航定位系统。 |
371| CONSTELLATION_CATEGORY_IRNSS     | 7 | IRNSS(Indian Regional Navigation Satellite System),即印度区域导航卫星系统,是一个由印度空间研究组织(ISRO)发展的自由区域型卫星导航系统。 |
372
373
374## SatelliteAdditionalInfo<sup>12+</sup>
375
376卫星附加信息类型。
377
378**系统能力**:SystemCapability.Location.Location.Gnss
379
380| 名称 | 值 | 说明 |
381| -------- | -------- | -------- |
382| SATELLITES_ADDITIONAL_INFO_NULL  | 0 | 默认值。 |
383| SATELLITES_ADDITIONAL_INFO_EPHEMERIS_DATA_EXIST  | 1 | 表示本卫星具有星历数据。 |
384| SATELLITES_ADDITIONAL_INFO_ALMANAC_DATA_EXIST   | 2 | 表示本卫星具有年历数据。 |
385| SATELLITES_ADDITIONAL_INFO_USED_IN_FIX   | 4 | 表示在最新的位置解算中使用了本卫星。 |
386| SATELLITES_ADDITIONAL_INFO_CARRIER_FREQUENCY_EXIST   | 8 | 表示本卫星具有载波频率。 |
387
388
389## PowerConsumptionScenario<sup>12+</sup>
390
391位置请求中的功耗场景类型。
392
393**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
394
395**系统能力**:SystemCapability.Location.Location.Core
396
397| 名称 | 值 | 说明 |
398| -------- | -------- | -------- |
399| HIGH_POWER_CONSUMPTION  | 0x601 | 高功耗。<br/>以GNSS定位技术为主。我们会在GNSS提供稳定位置结果之前使用网络定位技术提供服务;在持续定位时,如果超过30秒无法获取GNSS定位结果则会使用网络定位技术获取位置。对设备的硬件资源消耗较大,功耗较大。 |
400| LOW_POWER_CONSUMPTION  | 0x602 | 低功耗。<br/>适用于对用户位置精度要求不高的使用场景,如新闻资讯、网购、点餐类应用。<br/>该场景仅使用网络定位技术提供定位服务,功耗较低。 |
401| NO_POWER_CONSUMPTION   | 0x603 | 无功耗。<br/>这种场景下不会主动触发定位,会在其他应用定位时,才给当前应用返回位置。  |
402
403
404## UserActivityScenario<sup>12+</sup>
405
406位置请求中的用户活动场景类型。
407
408**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
409
410**系统能力**:SystemCapability.Location.Location.Core
411
412> **说明:**
413>
414> 当使用NAVIGATION/SPORT/TRANSPORT场景进行单次定位或持续定位时,我们会在GNSS提供稳定位置结果之前使用网络定位技术提供服务;在持续定位时,如果超过30秒无法获取GNSS定位结果则会使用网络定位技术获取位置。
415
416| 名称 | 值 | 说明 |
417| -------- | -------- | -------- |
418| NAVIGATION  | 0x401 | 表示导航场景。<br/>适用于在户外获取设备实时位置的场景,如车载、步行导航。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。 |
419| SPORT  | 0x402 | 表示运动场景。<br/>适用于记录用户位置轨迹的场景,如运动类应用记录轨迹功能。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。 |
420| TRANSPORT   | 0x403 | 表示出行场景。<br/>适用于用户出行场景,如打车、乘坐公共交通等场景。<br/>主要使用GNSS定位技术提供定位服务,功耗较高。  |
421| DAILY_LIFE_SERVICE   | 0x404 | 表示日常服务使用场景。<br/>适用于不需要定位用户精确位置的使用场景,如新闻资讯、网购、点餐类应用。<br/>该场景仅使用网络定位技术提供定位服务,功耗较低。  |
422
423
424## LocatingPriority<sup>12+</sup>
425
426单次位置请求中的优先级类型。
427
428**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
429
430**系统能力**:SystemCapability.Location.Location.Core
431
432| 名称 | 值 | 说明 |
433| -------- | -------- | -------- |
434| PRIORITY_ACCURACY  | 0x501 | 表示精度优先。<br/>定位精度优先策略会同时使用GNSS定位和网络定位技术,并把一段时间内精度较好的结果返回给应用;这个时间段长度为[SingleLocationRequest](#singlelocationrequest12).locatingTimeoutMs与“30秒”中的较小者。<br/>对设备的硬件资源消耗较大,功耗较大。  |
435| PRIORITY_LOCATING_SPEED  | 0x502 | 表示快速获取位置优先,如果应用希望快速拿到一个位置,可以将优先级设置为该类型。<br/>快速定位优先策略会同时使用GNSS定位和网络定位技术,以便在室内和户外场景下均可以快速获取到位置结果,我们会把最先拿到的定位结果返回给应用。对设备的硬件资源消耗较大,功耗也较大。 |
436
437
438## LocationError<sup>12+</sup>
439
440持续定位过程中的错误信息。
441
442**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
443
444**系统能力**:SystemCapability.Location.Location.Core
445
446| 名称 | 值 | 说明 |
447| -------- | -------- | -------- |
448| LOCATING_FAILED_DEFAULT   | -1 |  默认值。 |
449| LOCATING_FAILED_LOCATION_PERMISSION_DENIED   | -2 | 表示ohos.permission.APPROXIMATELY_LOCATION权限或ohos.permission.LOCATION权限校验失败导致持续定位失败。 |
450| LOCATING_FAILED_BACKGROUND_PERMISSION_DENIED    | -3 | 表示应用在后台时位置权限校验失败导致持续定位失败。APP在后台定位时的位置权限申请方式参见[申请位置权限开发指导](../../device/location/location-permission-guidelines.md#开发步骤)。 |
451| LOCATING_FAILED_LOCATION_SWITCH_OFF    | -4 | 表示位置信息开关关闭导致持续定位失败。 |
452| LOCATING_FAILED_INTERNET_ACCESS_FAILURE    | -5 | 表示无法访问网络,导致网络定位失败。 |
453
454
455## LocationSourceType<sup>12+</sup>
456
457定位结果的来源。
458
459**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
460
461**系统能力**:SystemCapability.Location.Location.Core
462
463| 名称 | 值 | 说明 |
464| -------- | -------- | -------- |
465| GNSS   | 1 |  表示定位结果来自于GNSS定位技术。 |
466| NETWORK    | 2 | 表示定位结果来自于网络定位技术。 |
467| INDOOR     | 3 | 表示定位结果来自于室内高精度定位技术。 |
468| RTK     | 4 | 表示定位结果来自于室外高精度定位技术。 |
469
470
471## geoLocationManager.on('locationChange')
472
473on(type: 'locationChange', request: LocationRequest | ContinuousLocationRequest, callback: Callback&lt;Location&gt;): void
474
475开启位置变化订阅,并发起定位请求。使用callback异步回调。
476
477**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
478
479**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
480
481**系统能力**:SystemCapability.Location.Location.Core
482
483**参数:**
484
485  | 参数名 | 类型 | 必填 | 说明 |
486  | -------- | -------- | -------- | -------- |
487  | type | string | 是 | 设置事件类型。type为“locationChange”,表示位置变化。 |
488  | request |  [LocationRequest](#locationrequest) &#124; [ContinuousLocationRequest](#continuouslocationrequest12) | 是 | 设置位置请求参数。<br/>ContinuousLocationRequest为API12新增参数。 |
489  | callback | Callback&lt;[Location](#location)&gt; | 是 | 回调函数,返回位置信息。 |
490
491**错误码**:
492
493以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
494
495| 错误码ID | 错误信息 |
496| -------- | ---------------------------------------- |
497|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
498|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
499|801 | Capability not supported. Failed to call ${geoLocationManager.on('locationChange')} due to limited device capabilities.          |
500|3301000 | The location service is unavailable.                                           |
501|3301100 | The location switch is off.                                                 |
502|3301200 | Failed to obtain the geographical location.                                       |
503
504**示例**
505
506  ```ts
507  import { geoLocationManager } from '@kit.LocationKit';
508
509  // 方式一:使用LocationRequest作为入参
510  let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
511  let locationChange = (location:geoLocationManager.Location):void => {
512      console.info('locationChanger: data: ' + JSON.stringify(location));
513  };
514  try {
515      geoLocationManager.on('locationChange', requestInfo, locationChange);
516  } catch (err) {
517      console.error("errCode:" + err.code + ", message:"  + err.message);
518  }
519
520  // 方式二:使用ContinuousLocationRequest作为入参
521  let request:geoLocationManager.ContinuousLocationRequest = {'interval': 1, 'locationScenario': geoLocationManager.UserActivityScenario.NAVIGATION};
522  let locationCallback = (location:geoLocationManager.Location):void => {
523      console.info('locationCallback: data: ' + JSON.stringify(location));
524  };
525  try {
526      geoLocationManager.on('locationChange', request, locationCallback);
527  } catch (err) {
528      console.error("errCode:" + err.code + ", message:"  + err.message);
529  }
530  ```
531
532
533## geoLocationManager.off('locationChange')
534
535off(type: 'locationChange', callback?: Callback&lt;Location&gt;): void
536
537关闭位置变化订阅,并删除对应的定位请求。
538
539**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
540
541**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
542
543**系统能力**:SystemCapability.Location.Location.Core
544
545**参数:**
546
547  | 参数名 | 类型 | 必填 | 说明 |
548  | -------- | -------- | -------- | -------- |
549  | type | string | 是 | 设置事件类型。type为“locationChange”,表示位置变化。 |
550  | callback | Callback&lt;[Location](#location)&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
551
552**错误码**:
553
554以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
555
556| 错误码ID | 错误信息 |
557| -------- | ---------------------------------------- |
558|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
559|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
560|801 | Capability not supported. Failed to call ${geoLocationManager.off('locationChange')} due to limited device capabilities.          |
561|3301000 | The location service is unavailable.                                           |
562|3301100 | The location switch is off.                                                 |
563|3301200 | Failed to obtain the geographical location.                                       |
564
565**示例**
566
567  ```ts
568  import { geoLocationManager } from '@kit.LocationKit';
569
570  let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
571  let locationChange = (location:geoLocationManager.Location):void => {
572    console.info('locationChanger: data: ' + JSON.stringify(location));
573  };
574  try {
575      geoLocationManager.on('locationChange', requestInfo, locationChange);
576      geoLocationManager.off('locationChange', locationChange);
577  } catch (err) {
578      console.error("errCode:" + err.code + ", message:"  + err.message);
579  }
580  ```
581
582
583## geoLocationManager.on('locationError')<sup>12+</sup>
584
585on(type: 'locationError', callback: Callback&lt;LocationError&gt;): void
586
587订阅持续定位过程中的错误码。使用callback异步回调。
588
589**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
590
591**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
592
593**系统能力**:SystemCapability.Location.Location.Core
594
595**参数:**
596
597  | 参数名 | 类型 | 必填 | 说明 |
598  | -------- | -------- | -------- | -------- |
599  | type | string | 是 | 设置事件类型。type为“locationError”,表示持续定位过程中的错误码变化。 |
600  | callback | Callback&lt;[LocationError](#locationerror12)&gt; | 是 | 回调函数,返回持续定位过程中的错误码。 |
601
602**错误码**:
603
604以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
605
606| 错误码ID | 错误信息 |
607| -------- | ---------------------------------------- |
608|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
609|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
610|801 | Capability not supported. Failed to call ${geoLocationManager.on('locationError')} due to limited device capabilities.          |
611|3301000 | The location service is unavailable.                                           |
612
613**示例**
614
615  ```ts
616  import { geoLocationManager } from '@kit.LocationKit';
617
618  let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
619  let locationChange = (location:geoLocationManager.Location):void => {
620      console.info('locationChanger: data: ' + JSON.stringify(location));
621  };
622  try {
623      geoLocationManager.on('locationChange', requestInfo, locationChange);
624  } catch (err) {
625      console.error("errCode:" + err.code + ", message:"  + err.message);
626  }
627
628  let locationErrorChange = (errcode: geoLocationManager.LocationError):void => {
629    console.info('locationErrorChange: data: ' + JSON.stringify(errcode));
630  };
631  try {
632    geoLocationManager.on('locationError', locationErrorChange);
633  } catch (err) {
634    console.error("errCode:" + err.code + ", message:"  + err.message);
635  }
636
637  ```
638
639
640## geoLocationManager.off('locationError')<sup>12+</sup>
641
642off(type: 'locationError', callback?: Callback&lt;LocationError&gt;): void
643
644取消订阅持续定位过程中的错误码。
645
646**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
647
648**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
649
650**系统能力**:SystemCapability.Location.Location.Core
651
652**参数:**
653
654  | 参数名 | 类型 | 必填 | 说明 |
655  | -------- | -------- | -------- | -------- |
656  | type | string | 是 | 设置事件类型。type为“locationError”,表示持续定位过程中的错误码变化。 |
657  | callback | Callback&lt;[LocationError](#locationerror12)&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
658
659**错误码**:
660
661以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
662
663| 错误码ID | 错误信息 |
664| -------- | ---------------------------------------- |
665|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
666|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
667|801 | Capability not supported. Failed to call ${geoLocationManager.off('locationError')} due to limited device capabilities.          |
668|3301000 | The location service is unavailable.                                           |
669
670**示例**
671
672  ```ts
673  import { geoLocationManager } from '@kit.LocationKit';
674
675  let locationErrorChange = (errcode: geoLocationManager.LocationError):void => {
676    console.info('locationErrorChange: data: ' + JSON.stringify(errcode));
677  };
678  try {
679    geoLocationManager.on('locationError', locationErrorChange);
680    geoLocationManager.off('locationError', locationErrorChange);
681  } catch (err) {
682    console.error("errCode:" + err.code + ", message:"  + err.message);
683  }
684  ```
685
686
687## geoLocationManager.on('locationEnabledChange')
688
689on(type: 'locationEnabledChange', callback: Callback&lt;boolean&gt;): void
690
691订阅位置服务状态变化。使用callback异步回调。
692
693**系统能力**:SystemCapability.Location.Location.Core
694
695**参数:**
696
697  | 参数名 | 类型 | 必填 | 说明 |
698  | -------- | -------- | -------- | -------- |
699  | type | string | 是 | 设置事件类型。type为“locationEnabledChange”,表示位置服务状态。 |
700  | callback | Callback&lt;boolean&gt; | 是 | 回调函数。返回true表示位置信息开关已经开启;返回false表示位置信息开关已经关闭。 |
701
702**错误码**:
703
704以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
705
706| 错误码ID | 错误信息 |
707| -------- | ---------------------------------------- |
708|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
709|801 | Capability not supported. Failed to call ${geoLocationManager.on('locationEnabledChange')} due to limited device capabilities.          |
710|3301000 | The location service is unavailable.                                           |
711
712**示例**
713
714  ```ts
715  import { geoLocationManager } from '@kit.LocationKit';
716
717  let locationEnabledChange = (state:boolean):void => {
718      console.info('locationEnabledChange: ' + JSON.stringify(state));
719  }
720  try {
721      geoLocationManager.on('locationEnabledChange', locationEnabledChange);
722  } catch (err) {
723      console.error("errCode:" + err.code + ", message:"  + err.message);
724  }
725  ```
726
727
728## geoLocationManager.off('locationEnabledChange')
729
730off(type: 'locationEnabledChange', callback?: Callback&lt;boolean&gt;): void
731
732取消订阅位置服务状态变化。
733
734**系统能力**:SystemCapability.Location.Location.Core
735
736**参数**:
737
738  | 参数名 | 类型 | 必填 | 说明 |
739  | -------- | -------- | -------- | -------- |
740  | type | string | 是 | 设置事件类型。type为“locationEnabledChange”,表示位置服务状态。 |
741  | callback | Callback&lt;boolean&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
742
743**错误码**:
744
745以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
746
747| 错误码ID | 错误信息 |
748| -------- | ---------------------------------------- |
749|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
750|801 | Capability not supported. Failed to call ${geoLocationManager.off('locationEnabledChange')} due to limited device capabilities.          |
751|3301000 | The location service is unavailable.                                           |
752
753**示例**
754
755  ```ts
756  import { geoLocationManager } from '@kit.LocationKit';
757
758  let locationEnabledChange = (state:boolean):void => {
759      console.info('locationEnabledChange: state: ' + JSON.stringify(state));
760  }
761  try {
762      geoLocationManager.on('locationEnabledChange', locationEnabledChange);
763      geoLocationManager.off('locationEnabledChange', locationEnabledChange);
764  } catch (err) {
765      console.error("errCode:" + err.code + ", message:"  + err.message);
766  }
767  ```
768
769
770## geoLocationManager.on('cachedGnssLocationsChange')
771
772on(type: 'cachedGnssLocationsChange', request: CachedGnssLocationsRequest, callback: Callback&lt;Array&lt;Location&gt;&gt;): void
773
774订阅缓存GNSS定位结果上报事件。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。使用callback异步回调。
775
776**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
777
778**系统能力**:SystemCapability.Location.Location.Gnss
779
780**参数**:
781
782  | 参数名 | 类型 | 必填 | 说明 |
783  | -------- | -------- | -------- | -------- |
784  | type | string | 是 | 设置事件类型。type为“cachedGnssLocationsChange”,表示GNSS缓存定位结果上报。 |
785  | request |  [CachedGnssLocationsRequest](#cachedgnsslocationsrequest) | 是 | GNSS缓存功能配置参数 |
786  | callback | Callback&lt;Array&lt;[Location](#location)&gt;&gt; | 是 | 回调函数,返回GNSS缓存位置。 |
787
788**错误码**:
789
790以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
791
792| 错误码ID | 错误信息 |
793| -------- | ---------------------------------------- |
794|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
795|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
796|801 | Capability not supported. Failed to call ${geoLocationManager.on('cachedGnssLocationsChange')} due to limited device capabilities.          |
797|3301000 | The location service is unavailable.                                           |
798|3301100 | The location switch is off.                                                 |
799|3301200 | Failed to obtain the geographical location.                                       |
800
801**示例**
802
803  ```ts
804  import { geoLocationManager } from '@kit.LocationKit';
805
806  let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => {
807      console.info('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
808  }
809  let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
810  try {
811      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
812  } catch (err) {
813      console.error("errCode:" + err.code + ", message:"  + err.message);
814  }
815  ```
816
817
818## geoLocationManager.off('cachedGnssLocationsChange')
819
820off(type: 'cachedGnssLocationsChange', callback?: Callback&lt;Array&lt;Location&gt;&gt;): void
821
822取消订阅缓存GNSS定位结果上报事件。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。
823
824**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
825
826**系统能力**:SystemCapability.Location.Location.Gnss
827
828**参数**:
829
830  | 参数名 | 类型 | 必填 | 说明 |
831  | -------- | -------- | -------- | -------- |
832  | type | string | 是 | 设置事件类型。type为“cachedGnssLocationsChange”,表示GNSS缓存定位结果上报。 |
833  | callback | Callback&lt;Array&lt;[Location](#location)&gt;&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
834
835**错误码**:
836
837以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
838
839| 错误码ID | 错误信息 |
840| -------- | ---------------------------------------- |
841|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
842|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
843|801 | Capability not supported. Failed to call ${geoLocationManager.off('cachedGnssLocationsChange')} due to limited device capabilities.          |
844|3301000 | The location service is unavailable.                                           |
845|3301100 | The location switch is off.                                                 |
846|3301200 | Failed to obtain the geographical location.                                       |
847
848**示例**
849
850  ```ts
851  import { geoLocationManager } from '@kit.LocationKit';
852
853  let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => {
854      console.info('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
855  }
856  let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
857  try {
858      geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
859      geoLocationManager.off('cachedGnssLocationsChange');
860  } catch (err) {
861      console.error("errCode:" + err.code + ", message:"  + err.message);
862  }
863  ```
864
865
866## geoLocationManager.on('satelliteStatusChange')
867
868on(type: 'satelliteStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;): void
869
870订阅GNSS卫星状态信息上报事件。使用callback异步回调。
871
872**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
873
874**系统能力**:SystemCapability.Location.Location.Gnss
875
876**参数**:
877
878  | 参数名 | 类型 | 必填 | 说明 |
879  | -------- | -------- | -------- | -------- |
880  | type | string | 是 | 设置事件类型。type为“satelliteStatusChange”,表示订阅GNSS卫星状态信息上报。 |
881  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | 是 | 回调函数,返回GNSS卫星状态信息。 |
882
883**错误码**:
884
885以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
886
887| 错误码ID | 错误信息 |
888| -------- | ---------------------------------------- |
889|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
890|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
891|801 | Capability not supported. Failed to call ${geoLocationManager.on('satelliteStatusChange')} due to limited device capabilities.          |
892|3301000 | The location service is unavailable.                                           |
893|3301100 | The location switch is off.                                                 |
894
895**示例**
896
897  ```ts
898  import { geoLocationManager } from '@kit.LocationKit';
899
900  let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => {
901      console.info('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
902  }
903
904  try {
905      geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
906  } catch (err) {
907      console.error("errCode:" + err.code + ", message:"  + err.message);
908  }
909  ```
910
911
912## geoLocationManager.off('satelliteStatusChange')
913
914off(type: 'satelliteStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;): void
915
916取消订阅GNSS卫星状态信息上报事件。
917
918**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
919
920**系统能力**:SystemCapability.Location.Location.Gnss
921
922**参数**:
923
924  | 参数名 | 类型 | 必填 | 说明 |
925  | -------- | -------- | -------- | -------- |
926  | type | string | 是 | 设置事件类型。type为“satelliteStatusChange”,表示订阅GNSS卫星状态信息上报。 |
927  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
928
929**错误码**:
930
931以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
932
933| 错误码ID | 错误信息 |
934| -------- | ---------------------------------------- |
935|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
936|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
937|801 | Capability not supported. Failed to call ${geoLocationManager.off('satelliteStatusChange')} due to limited device capabilities.          |
938|3301000 | The location service is unavailable.                                           |
939|3301100 | The location switch is off.                                                 |
940
941
942**示例**
943
944  ```ts
945  import { geoLocationManager } from '@kit.LocationKit';
946
947  let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => {
948      console.info('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
949  }
950  try {
951      geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
952      geoLocationManager.off('satelliteStatusChange', gnssStatusCb);
953  } catch (err) {
954      console.error("errCode:" + err.code + ", message:"  + err.message);
955  }
956  ```
957
958
959## geoLocationManager.on('nmeaMessage')
960
961on(type: 'nmeaMessage', callback: Callback&lt;string&gt;): void
962
963订阅GNSS NMEA信息上报事件。使用callback异步回调。
964
965**需要权限**:ohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
966
967**系统能力**:SystemCapability.Location.Location.Gnss
968
969**参数**:
970
971  | 参数名 | 类型 | 必填 | 说明 |
972  | -------- | -------- | -------- | -------- |
973  | type | string | 是 | 设置事件类型。type为“nmeaMessage”,表示订阅GNSS&nbsp;NMEA信息上报。 |
974  | callback | Callback&lt;string&gt; | 是 | 回调函数,返回GNSS&nbsp;NMEA信息。 |
975
976**错误码**:
977
978以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
979
980| 错误码ID | 错误信息 |
981| -------- | ---------------------------------------- |
982|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
983|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
984|801 | Capability not supported. Failed to call ${geoLocationManager.on('nmeaMessage')} due to limited device capabilities.          |
985|3301000 | The location service is unavailable.                                           |
986|3301100 | The location switch is off.                                                 |
987
988
989**示例**
990
991  ```ts
992  import { geoLocationManager } from '@kit.LocationKit';
993
994  let nmeaCb = (str:string):void => {
995      console.info('nmeaMessage: ' + JSON.stringify(str));
996  }
997
998  try {
999      geoLocationManager.on('nmeaMessage', nmeaCb );
1000  } catch (err) {
1001      console.error("errCode:" + err.code + ", message:"  + err.message);
1002  }
1003  ```
1004
1005
1006## geoLocationManager.off('nmeaMessage')
1007
1008off(type: 'nmeaMessage', callback?: Callback&lt;string&gt;): void
1009
1010取消订阅GNSS NMEA信息上报事件。
1011
1012**需要权限**:ohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
1013
1014**系统能力**:SystemCapability.Location.Location.Gnss
1015
1016**参数**:
1017
1018  | 参数名 | 类型 | 必填 | 说明 |
1019  | -------- | -------- | -------- | -------- |
1020  | type | string | 是 | 设置事件类型。type为“nmeaMessage”,表示订阅GNSS&nbsp;NMEA信息上报。 |
1021  | callback | Callback&lt;string&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
1022
1023**错误码**:
1024
1025以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1026
1027| 错误码ID | 错误信息 |
1028| -------- | ---------------------------------------- |
1029|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
1030|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1031|801 | Capability not supported. Failed to call ${geoLocationManager.off('nmeaMessage')} due to limited device capabilities.          |
1032|3301000 | The location service is unavailable.                                           |
1033|3301100 | The location switch is off.                                                 |
1034
1035
1036**示例**
1037
1038  ```ts
1039  import { geoLocationManager } from '@kit.LocationKit';
1040
1041  let nmeaCb = (str:string):void => {
1042      console.info('nmeaMessage: ' + JSON.stringify(str));
1043  }
1044
1045  try {
1046      geoLocationManager.on('nmeaMessage', nmeaCb);
1047      geoLocationManager.off('nmeaMessage', nmeaCb);
1048  } catch (err) {
1049      console.error("errCode:" + err.code + ", message:"  + err.message);
1050  }
1051  ```
1052
1053
1054## geoLocationManager.on('gnssFenceStatusChange')
1055
1056on(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void
1057
1058添加一个围栏,并订阅地理围栏事件。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。
1059
1060**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1061
1062**系统能力**:SystemCapability.Location.Location.Geofence
1063
1064**参数**:
1065
1066  | 参数名 | 类型 | 必填 | 说明 |
1067  | -------- | -------- | -------- | -------- |
1068  | type | string | 是 | 设置事件类型。type为“gnssFenceStatusChange”,表示订阅围栏事件上报。 |
1069  | request |  [GeofenceRequest](#geofencerequest) | 是 | 围栏的配置参数。 |
1070  | want | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | 是 | 用于接收地理围栏事件上报(进出围栏)。 |
1071
1072**错误码**:
1073
1074以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1075
1076| 错误码ID | 错误信息 |
1077| -------- | ---------------------------------------- |
1078|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
1079|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1080|801 | Capability not supported. Failed to call ${geoLocationManager.on('gnssFenceStatusChange')} due to limited device capabilities.          |
1081|3301000 | The location service is unavailable.                                           |
1082|3301100 | The location switch is off.                                                 |
1083|3301600 | Failed to operate the geofence.                                     |
1084
1085**示例**
1086
1087  ```ts
1088  import { geoLocationManager } from '@kit.LocationKit';
1089  import { wantAgent } from '@kit.AbilityKit';
1090
1091
1092  let wantAgentInfo:wantAgent.WantAgentInfo = {
1093      wants: [
1094          {
1095              bundleName: "com.example.myapplication",
1096              abilityName: "EntryAbility",
1097              action: "action1"
1098          }
1099      ],
1100      operationType: wantAgent.OperationType.START_ABILITY,
1101      requestCode: 0,
1102      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
1103  };
1104
1105  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
1106    let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 31.12, "longitude": 121.11, "radius": 100, "expiration": 10000}};
1107    try {
1108        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
1109    } catch (err) {
1110        console.error("errCode:" + err.code + ", message:"  + err.message);
1111    }
1112  });
1113  ```
1114
1115
1116## geoLocationManager.off('gnssFenceStatusChange')
1117
1118off(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void
1119
1120删除一个围栏,并取消订阅该围栏事件。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。
1121
1122**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1123
1124**系统能力**:SystemCapability.Location.Location.Geofence
1125
1126**参数**:
1127
1128  | 参数名 | 类型 | 必填 | 说明 |
1129  | -------- | -------- | -------- | -------- |
1130  | type | string | 是 | 设置事件类型。type为“gnssFenceStatusChange”,表示订阅围栏事件上报。 |
1131  | request | [GeofenceRequest](#geofencerequest) | 是 | 围栏的配置参数。 |
1132  | want | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | 是 | 用于接收地理围栏事件上报(进出围栏)。 |
1133
1134**错误码**:
1135
1136以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1137
1138| 错误码ID | 错误信息 |
1139| -------- | ---------------------------------------- |
1140|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
1141|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1142|801 | Capability not supported. Failed to call ${geoLocationManager.off('gnssFenceStatusChange')} due to limited device capabilities.          |
1143|3301000 | The location service is unavailable.                                           |
1144|3301100 | The location switch is off.                                                 |
1145|3301600 | Failed to operate the geofence.                                     |
1146
1147**示例**
1148
1149  ```ts
1150  import { geoLocationManager } from '@kit.LocationKit';
1151  import { wantAgent } from '@kit.AbilityKit';
1152
1153
1154  let wantAgentInfo:wantAgent.WantAgentInfo = {
1155      wants: [
1156          {
1157              bundleName: "com.example.myapplication",
1158              abilityName: "EntryAbility",
1159              action: "action1",
1160          }
1161      ],
1162      operationType: wantAgent.OperationType.START_ABILITY,
1163      requestCode: 0,
1164      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
1165  };
1166
1167  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
1168    let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 31.12, "longitude": 121.11, "radius": 100, "expiration": 10000}};;
1169    try {
1170        geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
1171        geoLocationManager.off('gnssFenceStatusChange', requestInfo, wantAgentObj);
1172    } catch (err) {
1173        console.error("errCode:" + err.code + ", message:"  + err.message);
1174    }
1175  });
1176  ```
1177
1178
1179## geoLocationManager.on('countryCodeChange')
1180
1181on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;): void
1182
1183订阅国家码信息变化事件。使用callback异步回调。
1184
1185**系统能力**:SystemCapability.Location.Location.Core
1186
1187**参数**:
1188
1189  | 参数名 | 类型 | 必填 | 说明 |
1190  | -------- | -------- | -------- | -------- |
1191  | type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示订阅国家码信息变化事件。 |
1192  | callback | Callback&lt;[CountryCode](#countrycode)&gt; | 是 | 回调函数,返回国家码信息。 |
1193
1194**错误码**:
1195
1196以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1197
1198| 错误码ID | 错误信息 |
1199| -------- | ---------------------------------------- |
1200|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1201|801 | Capability not supported. Failed to call ${geoLocationManager.on('countryCodeChange')} due to limited device capabilities.          |
1202|3301000 | The location service is unavailable.                                           |
1203|3301500 | Failed to query the area information.                                       |
1204
1205
1206**示例**
1207
1208  ```ts
1209  import { geoLocationManager } from '@kit.LocationKit';
1210
1211  let callback = (code:geoLocationManager.CountryCode):void => {
1212      console.info('countryCodeChange: ' + JSON.stringify(code));
1213  }
1214
1215  try {
1216      geoLocationManager.on('countryCodeChange', callback);
1217  } catch (err) {
1218      console.error("errCode:" + err.code + ", message:"  + err.message);
1219  }
1220  ```
1221
1222
1223## geoLocationManager.off('countryCodeChange')
1224
1225off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;): void
1226
1227取消订阅国家码变化事件。
1228
1229**系统能力**:SystemCapability.Location.Location.Core
1230
1231**参数**:
1232
1233  | 参数名 | 类型 | 必填 | 说明 |
1234  | -------- | -------- | -------- | -------- |
1235  | type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示取消订阅国家码信息变化事件。 |
1236  | callback | Callback&lt;[CountryCode](#countrycode)&gt; | 否 | 需要取消订阅的回调函数。该回调函数需要与on接口传入的回调函数保持一致。若无此参数,则取消当前类型的所有订阅。 |
1237
1238**错误码**:
1239
1240以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1241
1242| 错误码ID | 错误信息 |
1243| -------- | ---------------------------------------- |
1244|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1245|801 | Capability not supported. Failed to call ${geoLocationManager.off('countryCodeChange')} due to limited device capabilities.          |
1246|3301000 | The location service is unavailable.                                           |
1247|3301500 | Failed to query the area information.                                       |
1248
1249**示例**
1250
1251  ```ts
1252  import { geoLocationManager } from '@kit.LocationKit';
1253
1254  let callback = (code:geoLocationManager.CountryCode):void => {
1255      console.info('countryCodeChange: ' + JSON.stringify(code));
1256  }
1257
1258  try {
1259      geoLocationManager.on('countryCodeChange', callback);
1260      geoLocationManager.off('countryCodeChange', callback);
1261  } catch (err) {
1262      console.error("errCode:" + err.code + ", message:"  + err.message);
1263  }
1264  ```
1265
1266
1267## geoLocationManager.getCurrentLocation
1268
1269getCurrentLocation(request: CurrentLocationRequest | SingleLocationRequest, callback: AsyncCallback&lt;Location&gt;): void
1270
1271获取当前位置,使用callback异步回调。
1272
1273**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1274
1275**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1276
1277**系统能力**:SystemCapability.Location.Location.Core
1278
1279**参数**:
1280
1281  | 参数名 | 类型 | 必填 | 说明 |
1282  | -------- | -------- | -------- | -------- |
1283  | request | [CurrentLocationRequest](#currentlocationrequest) &#124;  [SingleLocationRequest](#singlelocationrequest12) | 是 | 设置位置请求参数。<br/>SingleLocationRequest为API12新增参数。 |
1284  | callback | AsyncCallback&lt;[Location](#location)&gt; | 是 | 回调函数,返回当前位置信息。 |
1285
1286**错误码**:
1287
1288以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1289
1290| 错误码ID | 错误信息 |
1291| -------- | ---------------------------------------- |
1292|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
1293|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1294|801 | Capability not supported. Failed to call ${geoLocationManager.getCurrentLocation} due to limited device capabilities.          |
1295|3301000 | The location service is unavailable.                                           |
1296|3301100 | The location switch is off.                                                 |
1297|3301200 | Failed to obtain the geographical location.  |
1298
1299**示例**
1300
1301  ```ts
1302  import { geoLocationManager } from '@kit.LocationKit';
1303  import { BusinessError } from '@kit.BasicServicesKit';
1304  // 方式一:使用CurrentLocationRequest作为入参
1305  let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
1306  let locationChange = (err:BusinessError, location:geoLocationManager.Location):void => {
1307      if (err) {
1308          console.error('locationChanger: err=' + JSON.stringify(err));
1309      }
1310      if (location) {
1311          console.info('locationChanger: location=' + JSON.stringify(location));
1312      }
1313  };
1314
1315  try {
1316      geoLocationManager.getCurrentLocation(requestInfo, locationChange);
1317  } catch (err) {
1318      console.error("errCode:" + err.code + ", message:"  + err.message);
1319  }
1320
1321  // 方式二:使用SingleLocationRequest作为入参
1322  let request:geoLocationManager.SingleLocationRequest = {'locatingTimeoutMs': 10000, 'locatingPriority': geoLocationManager.LocatingPriority.PRIORITY_ACCURACY};
1323  let locationCallback = (err:BusinessError, location:geoLocationManager.Location):void => {
1324      if (err) {
1325          console.error('locationChanger: err=' + JSON.stringify(err));
1326      }
1327      if (location) {
1328          console.info('locationChanger: location=' + JSON.stringify(location));
1329      }
1330  };
1331
1332  try {
1333      geoLocationManager.getCurrentLocation(request, locationCallback);
1334  } catch (err) {
1335      console.error("errCode:" + err.code + ", message:"  + err.message);
1336  }
1337  ```
1338
1339## geoLocationManager.getCurrentLocation
1340
1341getCurrentLocation(callback: AsyncCallback&lt;Location&gt;): void
1342
1343获取当前位置,使用callback异步回调。
1344
1345**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1346
1347**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1348
1349**系统能力**:SystemCapability.Location.Location.Core
1350
1351**参数**:
1352
1353  | 参数名 | 类型 | 必填 | 说明 |
1354  | -------- | -------- | -------- | -------- |
1355  | callback | AsyncCallback&lt;[Location](#location)&gt; | 是 | 回调函数,返回当前位置信息。 |
1356
1357**错误码**:
1358
1359以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1360
1361| 错误码ID | 错误信息 |
1362| -------- | ---------------------------------------- |
1363|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
1364|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1365|801 | Capability not supported. Failed to call ${geoLocationManager.getCurrentLocation} due to limited device capabilities.          |
1366|3301000 | The location service is unavailable.                                           |
1367|3301100 | The location switch is off.                                                 |
1368|3301200 | Failed to obtain the geographical location.  |
1369
1370**示例**
1371
1372  ```ts
1373  import { geoLocationManager } from '@kit.LocationKit';
1374  import { BusinessError } from '@kit.BasicServicesKit';
1375  let locationChange = (err:BusinessError, location:geoLocationManager.Location) => {
1376      if (err) {
1377          console.error('locationChanger: err=' + JSON.stringify(err));
1378      }
1379      if (location) {
1380          console.info('locationChanger: location=' + JSON.stringify(location));
1381      }
1382  };
1383
1384  try {
1385      geoLocationManager.getCurrentLocation(locationChange);
1386  } catch (err) {
1387      console.error("errCode:" + err.code + ", message:"  + err.message);
1388  }
1389  ```
1390
1391## geoLocationManager.getCurrentLocation
1392
1393getCurrentLocation(request?: CurrentLocationRequest | SingleLocationRequest): Promise&lt;Location&gt;
1394
1395获取当前位置,使用Promise异步回调。
1396
1397**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1398
1399**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1400
1401**系统能力**:SystemCapability.Location.Location.Core
1402
1403**参数**:
1404
1405  | 参数名 | 类型 | 必填 | 说明 |
1406  | -------- | -------- | -------- | -------- |
1407  | request | [CurrentLocationRequest](#currentlocationrequest) &#124; [SingleLocationRequest](#singlelocationrequest12) | 否 | 设置位置请求参数。<br/>SingleLocationRequest为API12新增参数。 |
1408
1409**返回值**:
1410
1411  | 类型 | 说明 |
1412  | -------- | -------- |
1413  | Promise&lt;[Location](#location)&gt; | Promise对象,返回当前位置信息。 |
1414
1415**错误码**:
1416
1417以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1418
1419| 错误码ID | 错误信息 |
1420| -------- | ---------------------------------------- |
1421|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
1422|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1423|801 | Capability not supported. Failed to call ${geoLocationManager.getCurrentLocation} due to limited device capabilities.          |
1424|3301000 | The location service is unavailable.                                           |
1425|3301100 | The location switch is off.                                                 |
1426|3301200 | Failed to obtain the geographical location.  |
1427
1428**示例**
1429
1430  ```ts
1431  import { geoLocationManager } from '@kit.LocationKit';
1432  import { BusinessError } from '@kit.BasicServicesKit';
1433
1434  // 方式一:使用CurrentLocationRequest作为入参
1435  let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
1436  try {
1437      geoLocationManager.getCurrentLocation(requestInfo).then((result) => {
1438          console.info('current location: ' + JSON.stringify(result));
1439      })
1440      .catch((error:BusinessError) => {
1441          console.error('promise, getCurrentLocation: error=' + JSON.stringify(error));
1442      });
1443  } catch (err) {
1444      console.error("errCode:" + err.code + ", message:"  + err.message);
1445  }
1446
1447  // 方式二:使用SingleLocationRequest作为入参
1448  let request:geoLocationManager.SingleLocationRequest = {'locatingTimeoutMs': 10000, 'locatingPriority': geoLocationManager.LocatingPriority.PRIORITY_ACCURACY};
1449  try {
1450      geoLocationManager.getCurrentLocation(request).then((result) => {
1451          console.info('current location: ' + JSON.stringify(result));
1452      })
1453      .catch((error:BusinessError) => {
1454          console.error('promise, getCurrentLocation: error=' + JSON.stringify(error));
1455      });
1456  } catch (err) {
1457      console.error("errCode:" + err.code + ", message:"  + err.message);
1458  }
1459  ```
1460
1461
1462## geoLocationManager.getLastLocation
1463
1464getLastLocation(): Location
1465
1466获取上一次位置。
1467
1468**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1469
1470**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1471
1472**系统能力**:SystemCapability.Location.Location.Core
1473
1474**返回值**:
1475
1476  | 类型 | 说明 |
1477  | -------- | -------- |
1478  | [Location](#location) | 位置信息。 |
1479
1480**错误码**:
1481
1482以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1483
1484| 错误码ID | 错误信息 |
1485| -------- | ---------------------------------------- |
1486|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
1487|801 | Capability not supported. Failed to call ${geoLocationManager.getLastLocation} due to limited device capabilities.          |
1488|3301000 | The location service is unavailable. |
1489|3301100 | The location switch is off.  |
1490|3301200 |Failed to obtain the geographical location.  |
1491
1492**示例**
1493
1494  ```ts
1495  import { geoLocationManager } from '@kit.LocationKit';
1496  try {
1497      let location = geoLocationManager.getLastLocation();
1498  } catch (err) {
1499      console.error("errCode:" + err.code + ", message:"  + err.message);
1500  }
1501  ```
1502
1503
1504## geoLocationManager.isLocationEnabled
1505
1506isLocationEnabled(): boolean
1507
1508判断位置服务是否已经开启。
1509
1510**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1511
1512**系统能力**:SystemCapability.Location.Location.Core
1513
1514**返回值**:
1515
1516  | 类型 | 说明 |
1517  | -------- | -------- |
1518  | boolean | true:位置信息开关已开启<br/>false:位置信息开关已关闭 |
1519
1520**错误码**:
1521
1522以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1523
1524| 错误码ID | 错误信息 |
1525| -------- | ---------------------------------------- |
1526|801 | Capability not supported. Failed to call ${geoLocationManager.isLocationEnabled} due to limited device capabilities.          |
1527|3301000 | The location service is unavailable. |
1528
1529**示例**
1530
1531  ```ts
1532  import { geoLocationManager } from '@kit.LocationKit';
1533  try {
1534      let locationEnabled = geoLocationManager.isLocationEnabled();
1535  } catch (err) {
1536      console.error("errCode:" + err.code + ", message:"  + err.message);
1537  }
1538  ```
1539
1540
1541## geoLocationManager.getAddressesFromLocation
1542
1543getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
1544
1545调用逆地理编码服务,将坐标转换为地理描述,使用callback异步回调。
1546
1547**系统能力**:SystemCapability.Location.Location.Geocoder
1548
1549**参数**:
1550
1551  | 参数名 | 类型 | 必填 | 说明 |
1552  | -------- | -------- | -------- | -------- |
1553  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 设置逆地理编码请求的相关参数。 |
1554  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 是 | 回调函数,返回逆地理编码结果。 |
1555
1556**错误码**:
1557
1558以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1559
1560| 错误码ID | 错误信息 |
1561| -------- | ---------------------------------------- |
1562|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1563|801 | Capability not supported. Failed to call ${geoLocationManager.getAddressesFromLocation} due to limited device capabilities.          |
1564|3301000 | The location service is unavailable.  |
1565|3301300 | Reverse geocoding query failed.   |
1566
1567**示例**
1568
1569  ```ts
1570  import { geoLocationManager } from '@kit.LocationKit';
1571  let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
1572  try {
1573      geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
1574          if (err) {
1575              console.error('getAddressesFromLocation: err=' + JSON.stringify(err));
1576          }
1577          if (data) {
1578              console.info('getAddressesFromLocation: data=' + JSON.stringify(data));
1579          }
1580      });
1581  } catch (err) {
1582      console.error("errCode:" + err.code + ", message:"  + err.message);
1583  }
1584  ```
1585
1586
1587## geoLocationManager.getAddressesFromLocation
1588
1589getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;
1590
1591调用逆地理编码服务,将坐标转换为地理描述,使用Promise异步回调。
1592
1593**系统能力**:SystemCapability.Location.Location.Geocoder
1594
1595**参数**:
1596
1597  | 参数名 | 类型 | 必填 | 说明 |
1598  | -------- | -------- | -------- | -------- |
1599  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 设置逆地理编码请求的相关参数。 |
1600
1601**返回值**:
1602
1603  | 类型 | 说明 |
1604  | -------- | -------- |
1605  | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Promise对象,返回地理描述信息。 |
1606
1607**错误码**:
1608
1609以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1610
1611| 错误码ID | 错误信息 |
1612| -------- | ---------------------------------------- |
1613|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1614|801 | Capability not supported. Failed to call ${geoLocationManager.getAddressesFromLocation} due to limited device capabilities.          |
1615|3301000 | The location service is unavailable.  |
1616|3301300 | Reverse geocoding query failed.   |
1617
1618**示例**
1619
1620  ```ts
1621  import { geoLocationManager } from '@kit.LocationKit';
1622  import { BusinessError } from '@kit.BasicServicesKit';
1623  let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
1624  try {
1625      geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
1626          console.info('getAddressesFromLocation: ' + JSON.stringify(data));
1627      })
1628      .catch((error:BusinessError) => {
1629          console.error('promise, getAddressesFromLocation: error=' + JSON.stringify(error));
1630      });
1631  } catch (err) {
1632      console.error("errCode:" + err.code + ", message:"  + err.message);
1633  }
1634  ```
1635
1636
1637## geoLocationManager.getAddressesFromLocationName
1638
1639getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
1640
1641调用地理编码服务,将地理描述转换为具体坐标,使用callback异步回调。
1642
1643**系统能力**:SystemCapability.Location.Location.Geocoder
1644
1645**参数**:
1646
1647  | 参数名 | 类型 | 必填 | 说明 |
1648  | -------- | -------- | -------- | -------- |
1649  | request | [GeoCodeRequest](#geocoderequest) | 是 | 设置地理编码请求的相关参数。 |
1650  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 是 | 回调函数,返回地理编码结果。 |
1651
1652**错误码**:
1653
1654以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1655
1656| 错误码ID | 错误信息 |
1657| -------- | ---------------------------------------- |
1658|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1659|801 | Capability not supported. Failed to call ${geoLocationManager.getAddressesFromLocationName} due to limited device capabilities.          |
1660|3301000 | The location service is unavailable.  |
1661|3301400 | Geocoding query failed.   |
1662
1663**示例**
1664
1665  ```ts
1666  import { geoLocationManager } from '@kit.LocationKit';
1667  let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
1668  try {
1669      geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => {
1670          if (err) {
1671              console.error('getAddressesFromLocationName: err=' + JSON.stringify(err));
1672          }
1673          if (data) {
1674              console.info('getAddressesFromLocationName: data=' + JSON.stringify(data));
1675          }
1676      });
1677  } catch (err) {
1678      console.error("errCode:" + err.code + ", message:"  + err.message);
1679  }
1680  ```
1681
1682
1683## geoLocationManager.getAddressesFromLocationName
1684
1685getAddressesFromLocationName(request: GeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;
1686
1687调用地理编码服务,将地理描述转换为具体坐标,使用Promise异步回调。
1688
1689**系统能力**:SystemCapability.Location.Location.Geocoder
1690
1691**参数**:
1692
1693  | 参数名 | 类型 | 必填 | 说明 |
1694  | -------- | -------- | -------- | -------- |
1695  | request | [GeoCodeRequest](#geocoderequest) | 是 | 设置地理编码请求的相关参数。 |
1696
1697**返回值**:
1698
1699  | 类型 | 说明 |
1700  | -------- | -------- |
1701  | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Promise对象,返回地理编码查询结果。 |
1702
1703**错误码**:
1704
1705以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1706
1707| 错误码ID | 错误信息 |
1708| -------- | ---------------------------------------- |
1709|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1710|801 | Capability not supported. Failed to call ${geoLocationManager.getAddressesFromLocationName} due to limited device capabilities.          |
1711|3301000 | The location service is unavailable.  |
1712|3301400 | Geocoding query failed.   |
1713
1714**示例**
1715
1716  ```ts
1717  import { geoLocationManager } from '@kit.LocationKit';
1718  import { BusinessError } from '@kit.BasicServicesKit';
1719  let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
1720  try {
1721      geoLocationManager.getAddressesFromLocationName(geocodeRequest).then((result) => {
1722          console.info('getAddressesFromLocationName: ' + JSON.stringify(result));
1723      })
1724      .catch((error:BusinessError) => {
1725          console.error('promise, getAddressesFromLocationName: error=' + JSON.stringify(error));
1726      });
1727  } catch (err) {
1728      console.error("errCode:" + err.code + ", message:"  + err.message);
1729  }
1730  ```
1731
1732## geoLocationManager.isGeocoderAvailable
1733
1734isGeocoderAvailable(): boolean
1735
1736判断地理编码与逆地理编码服务状态。
1737
1738**系统能力**:SystemCapability.Location.Location.Geocoder
1739
1740**返回值**:
1741
1742  | 类型 | 说明 |
1743  | -------- | -------- |
1744  | boolean | true:地理编码与逆地理编码服务可用<br/>false:地理编码与逆地理编码服务不可用。 |
1745
1746**错误码**:
1747
1748以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1749
1750| 错误码ID | 错误信息 |
1751| -------- | ---------------------------------------- |
1752|801 | Capability not supported. Failed to call ${geoLocationManager.isGeocoderAvailable} due to limited device capabilities.          |
1753|3301000 | The location service is unavailable.  |
1754
1755**示例**
1756
1757  ```ts
1758  import { geoLocationManager } from '@kit.LocationKit';
1759  try {
1760      let isAvailable = geoLocationManager.isGeocoderAvailable();
1761  } catch (err) {
1762      console.error("errCode:" + err.code + ", message:"  + err.message);
1763  }
1764  ```
1765
1766
1767## geoLocationManager.getCachedGnssLocationsSize
1768
1769getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;): void
1770
1771获取GNSS芯片缓存位置的个数。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。使用callback异步回调。
1772
1773**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1774
1775**系统能力**:SystemCapability.Location.Location.Gnss
1776
1777**参数**:
1778
1779  | 参数名 | 类型 | 必填 | 说明 |
1780  | -------- | -------- | -------- | -------- |
1781  | callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回GNSS芯片缓存位置个数。 |
1782
1783**错误码**:
1784
1785以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1786
1787| 错误码ID | 错误信息 |
1788| -------- | ---------------------------------------- |
1789|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
1790|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1791|801 | Capability not supported. Failed to call ${geoLocationManager.getCachedGnssLocationsSize} due to limited device capabilities.          |
1792|3301000 | The location service is unavailable.  |
1793|3301100 | The location switch is off.   |
1794
1795**示例**
1796
1797  ```ts
1798  import { geoLocationManager } from '@kit.LocationKit';
1799  try {
1800      geoLocationManager.getCachedGnssLocationsSize((err, size) => {
1801          if (err) {
1802              console.error('getCachedGnssLocationsSize: err=' + JSON.stringify(err));
1803          }
1804          if (size) {
1805              console.info('getCachedGnssLocationsSize: size=' + JSON.stringify(size));
1806          }
1807      });
1808  } catch (err) {
1809      console.error("errCode:" + err.code + ", message:"  + err.message);
1810  }
1811  ```
1812
1813
1814## geoLocationManager.getCachedGnssLocationsSize
1815
1816getCachedGnssLocationsSize(): Promise&lt;number&gt;
1817
1818获取GNSS芯片缓存位置的个数。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。使用Promise异步回调。
1819
1820**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1821
1822**系统能力**:SystemCapability.Location.Location.Gnss
1823
1824**返回值**:
1825
1826  | 类型 | 说明 |
1827  | -------- | -------- |
1828  | Promise&lt;number&gt; | Promise对象,返回GNSS缓存位置的个数。 |
1829
1830**错误码**:
1831
1832以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1833
1834| 错误码ID | 错误信息 |
1835| -------- | ---------------------------------------- |
1836|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
1837|801 | Capability not supported. Failed to call ${geoLocationManager.getCachedGnssLocationsSize} due to limited device capabilities.          |
1838|3301000 | The location service is unavailable.  |
1839|3301100 | The location switch is off.   |
1840
1841**示例**
1842
1843  ```ts
1844  import { geoLocationManager } from '@kit.LocationKit';
1845  import { BusinessError } from '@kit.BasicServicesKit';
1846  try {
1847      geoLocationManager.getCachedGnssLocationsSize().then((result) => {
1848          console.info('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
1849      })
1850      .catch((error:BusinessError) => {
1851          console.error('promise, getCachedGnssLocationsSize: error=' + JSON.stringify(error));
1852      });
1853  } catch (err) {
1854      console.error("errCode:" + err.code + ", message:"  + err.message);
1855  }
1856  ```
1857
1858
1859## geoLocationManager.flushCachedGnssLocations
1860
1861flushCachedGnssLocations(callback: AsyncCallback&lt;void&gt;): void
1862
1863读取并清空GNSS芯片所有缓存位置。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。使用callback异步回调。
1864
1865**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1866
1867**系统能力**:SystemCapability.Location.Location.Gnss
1868
1869**参数**:
1870
1871  | 参数名 | 类型 | 必填 | 说明 |
1872  | -------- | -------- | -------- | -------- |
1873  | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当操作成功,err为undefined,否则为错误对象。 |
1874
1875**错误码**:
1876
1877以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1878
1879| 错误码ID | 错误信息 |
1880| -------- | ---------------------------------------- |
1881|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
1882|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1883|801 | Capability not supported. Failed to call ${geoLocationManager.flushCachedGnssLocations} due to limited device capabilities.          |
1884|3301000 | The location service is unavailable.  |
1885|3301100 | The location switch is off.   |
1886|3301200 | Failed to obtain the geographical location.   |
1887
1888**示例**
1889
1890  ```ts
1891  import { geoLocationManager } from '@kit.LocationKit';
1892  try {
1893      geoLocationManager.flushCachedGnssLocations((err) => {
1894          if (err) {
1895              console.error('flushCachedGnssLocations: err=' + JSON.stringify(err));
1896          }
1897      });
1898  } catch (err) {
1899      console.error("errCode:" + err.code + ", message:"  + err.message);
1900  }
1901  ```
1902
1903
1904## geoLocationManager.flushCachedGnssLocations
1905
1906flushCachedGnssLocations(): Promise&lt;void&gt;
1907
1908读取并清空GNSS芯片所有缓存位置。该接口功能由GNSS定位芯片提供(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。使用Promise异步回调。
1909
1910**需要权限**:ohos.permission.APPROXIMATELY_LOCATION
1911
1912**系统能力**:SystemCapability.Location.Location.Gnss
1913
1914**返回值**:
1915
1916  | 类型 | 说明 |
1917  | -------- | -------- |
1918  | Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象 |
1919
1920**错误码**:
1921
1922以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1923
1924| 错误码ID | 错误信息 |
1925| -------- | ---------------------------------------- |
1926|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
1927|801 | Capability not supported. Failed to call ${geoLocationManager.flushCachedGnssLocations} due to limited device capabilities.          |
1928|3301000 | The location service is unavailable.  |
1929|3301100 | The location switch is off.   |
1930|3301200 | Failed to obtain the geographical location.   |
1931
1932**示例**
1933
1934  ```ts
1935  import { geoLocationManager } from '@kit.LocationKit';
1936  import { BusinessError } from '@kit.BasicServicesKit';
1937  try {
1938      geoLocationManager.flushCachedGnssLocations().then(() => {
1939          console.info('promise, flushCachedGnssLocations success');
1940      })
1941      .catch((error:BusinessError) => {
1942          console.error('promise, flushCachedGnssLocations: error=' + JSON.stringify(error));
1943      });
1944  } catch (err) {
1945      console.error("errCode:" + err.code + ", message:"  + err.message);
1946  }
1947  ```
1948
1949
1950## geoLocationManager.sendCommand
1951
1952sendCommand(command: LocationCommand, callback: AsyncCallback&lt;void&gt;): void
1953
1954给位置服务子系统的各个部件发送扩展命令。使用callback异步回调。
1955
1956**系统能力**:SystemCapability.Location.Location.Core
1957
1958**参数**:
1959
1960  | 参数名 | 类型 | 必填 | 说明 |
1961  | -------- | -------- | -------- | -------- |
1962  | command |  [LocationCommand](#locationcommand) | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
1963  | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当命令发送成功,err为undefined,否则为错误对象。 |
1964
1965**错误码**:
1966
1967以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
1968
1969| 错误码ID | 错误信息 |
1970| -------- | ---------------------------------------- |
1971|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
1972|801 | Capability not supported. Failed to call ${geoLocationManager.sendCommand} due to limited device capabilities.          |
1973|3301000 | The location service is unavailable.  |
1974
1975**示例**
1976
1977  ```ts
1978  import { geoLocationManager } from '@kit.LocationKit';
1979  let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
1980  try {
1981      geoLocationManager.sendCommand(requestInfo, (err) => {
1982          if (err) {
1983              console.error('sendCommand: err=' + JSON.stringify(err));
1984          }
1985      });
1986  } catch (err) {
1987      console.error("errCode:" + err.code + ", message:"  + err.message);
1988  }
1989  ```
1990
1991
1992## geoLocationManager.sendCommand
1993
1994sendCommand(command: LocationCommand): Promise&lt;void&gt;
1995
1996给位置服务子系统的各个部件发送扩展命令。使用Promise异步回调。
1997
1998**系统能力**:SystemCapability.Location.Location.Core
1999
2000**参数**:
2001
2002  | 参数名 | 类型 | 必填 | 说明 |
2003  | -------- | -------- | -------- | -------- |
2004  | command | [LocationCommand](#locationcommand) | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
2005
2006**返回值**:
2007
2008  | 类型 | 说明 |
2009  | -------- | -------- |
2010  | Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象 |
2011
2012**错误码**:
2013
2014以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2015
2016| 错误码ID | 错误信息 |
2017| -------- | ---------------------------------------- |
2018|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
2019|801 | Capability not supported. Failed to call ${geoLocationManager.sendCommand} due to limited device capabilities.          |
2020|3301000 | The location service is unavailable.                                           |
2021
2022**示例**
2023
2024  ```ts
2025  import { geoLocationManager } from '@kit.LocationKit';
2026  import { BusinessError } from '@kit.BasicServicesKit';
2027  let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
2028  try {
2029      geoLocationManager.sendCommand(requestInfo).then(() => {
2030          console.info('promise, sendCommand success');
2031      })
2032      .catch((error:BusinessError) => {
2033          console.error('promise, sendCommand: error=' + JSON.stringify(error));
2034      });
2035  } catch (err) {
2036      console.error("errCode:" + err.code + ", message:"  + err.message);
2037  }
2038  ```
2039
2040
2041## geoLocationManager.getCountryCode
2042
2043getCountryCode(callback: AsyncCallback&lt;CountryCode&gt;): void
2044
2045查询当前的国家码。使用callback异步回调。
2046
2047**系统能力**:SystemCapability.Location.Location.Core
2048
2049**参数**:
2050
2051  | 参数名 | 类型 | 必填 | 说明 |
2052  | -------- | -------- | -------- | -------- |
2053  | callback | AsyncCallback&lt;[CountryCode](#countrycode)&gt; | 是 | 回调函数,返回国家码信息。 |
2054
2055**错误码**:
2056
2057以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2058
2059| 错误码ID | 错误信息 |
2060| -------- | ---------------------------------------- |
2061|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
2062|801 | Capability not supported. Failed to call ${geoLocationManager.getCountryCode} due to limited device capabilities.          |
2063|3301000 | The location service is unavailable.                                           |
2064|3301500 | Failed to query the area information.|
2065
2066**示例**
2067
2068  ```ts
2069  import { geoLocationManager } from '@kit.LocationKit';
2070  try {
2071      geoLocationManager.getCountryCode((err, result) => {
2072          if (err) {
2073              console.error('getCountryCode: err=' + JSON.stringify(err));
2074          }
2075          if (result) {
2076              console.info('getCountryCode: result=' + JSON.stringify(result));
2077          }
2078      });
2079  } catch (err) {
2080      console.error("errCode:" + err.code + ", message:"  + err.message);
2081  }
2082  ```
2083
2084
2085## geoLocationManager.getCountryCode
2086
2087getCountryCode(): Promise&lt;CountryCode&gt;
2088
2089查询当前的国家码。使用Promise异步回调。
2090
2091**系统能力**:SystemCapability.Location.Location.Core
2092
2093**返回值**:
2094
2095  | 类型 | 说明 |
2096  | -------- | -------- |
2097  | Promise&lt;[CountryCode](#countrycode)&gt; | Promise对象,返回国家码信息。 |
2098
2099**错误码**:
2100
2101以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2102
2103| 错误码ID | 错误信息 |
2104| -------- | ---------------------------------------- |
2105|801 | Capability not supported. Failed to call ${geoLocationManager.getCountryCode} due to limited device capabilities.          |
2106|3301000 | The location service is unavailable.                                           |
2107|3301500 | Failed to query the area information.|
2108
2109**示例**
2110
2111  ```ts
2112  import { geoLocationManager } from '@kit.LocationKit';
2113  import { BusinessError } from '@kit.BasicServicesKit';
2114  try {
2115      geoLocationManager.getCountryCode()
2116      .then((result) => {
2117          console.info('promise, getCountryCode: result=' + JSON.stringify(result));
2118      })
2119      .catch((error:BusinessError) => {
2120          console.error('promise, getCountryCode: error=' + JSON.stringify(error));
2121      });
2122  } catch (err) {
2123      console.error("errCode:" + err.code + ", message:"  + err.message);
2124  }
2125  ```
2126
2127## geoLocationManager.addGnssGeofence<sup>12+</sup>
2128
2129addGnssGeofence(fenceRequest: GnssGeofenceRequest): Promise&lt;number&gt;
2130
2131添加一个GNSS地理围栏,并订阅地理围栏事件。使用Promise异步回调。
2132
2133APP可以在入参[GnssGeofenceRequest](#gnssgeofencerequest12)中传入回调函数用于接收地理围栏事件;也可以传入通知对象[NotificationRequest](../apis-notification-kit/js-apis-notification.md#notificationrequest),在系统识别到地理围栏事件发生时会弹出APP创建的通知。
2134
2135GNSS地理围栏功能依赖GNSS定位芯片(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。
2136
2137**需要权限**:ohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
2138
2139**系统能力**:SystemCapability.Location.Location.Geofence
2140
2141**参数**:
2142
2143  | 参数名 | 类型 | 必填 | 说明 |
2144  | -------- | -------- | -------- | -------- |
2145  | fenceRequest | [GnssGeofenceRequest](#gnssgeofencerequest12) | 是 | 添加GNSS地理围栏请求参数。<br/>包含圆形围栏信息、需要监听的地理围栏事件、地理围栏事件触发后弹出的通知对象和监听地理围栏事件的回调函数。 |
2146
2147**返回值**:
2148
2149  | 类型 | 说明 |
2150  | -------- | -------- |
2151  | Promise&lt;number&gt; | Promise对象,返回地理围栏ID。 |
2152
2153**错误码**:
2154
2155以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2156
2157| 错误码ID | 错误信息 |
2158| -------- | ---------------------------------------- |
2159|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
2160|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
2161|801 | Capability not supported. Failed to call ${geoLocationManager.addGnssGeofence} due to limited device capabilities.          |
2162|3301000 | The location service is unavailable.|
2163|3301100  | The location switch is off.|
2164|3301601   | The number of geofences exceeds the maximum.|
2165
2166**示例**
2167
2168  ```ts
2169  import { geoLocationManager } from '@kit.LocationKit';
2170  import { BusinessError } from '@kit.BasicServicesKit';
2171  import { notificationManager } from '@kit.NotificationKit';
2172  // 创建围栏
2173  let geofence: geoLocationManager.Geofence = {
2174    "latitude": 34.12, "longitude": 124.11, "radius": 10000.0, "expiration": 10000.0
2175  }
2176  // 指定APP需要监听的地理围栏事件类型,这里表示需要监听进入围栏和退出围栏事件
2177  let transitionStatusList: Array<geoLocationManager.GeofenceTransitionEvent> = [
2178    geoLocationManager.GeofenceTransitionEvent.GEOFENCE_TRANSITION_EVENT_ENTER,
2179    geoLocationManager.GeofenceTransitionEvent.GEOFENCE_TRANSITION_EVENT_EXIT,
2180  ];
2181  // 创建GEOFENCE_TRANSITION_EVENT_ENTER事件对应的通知对象
2182  let notificationRequest1: notificationManager.NotificationRequest = {
2183    id: 1,
2184    content: {
2185      notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
2186      normal: {
2187        title: "围栏通知",
2188        text: "围栏进入",
2189        additionalText: ""
2190      }
2191    }
2192  };
2193  // 创建GEOFENCE_TRANSITION_EVENT_EXIT事件对应的通知对象
2194  let notificationRequest2: notificationManager.NotificationRequest = {
2195    id: 2,
2196    content: {
2197      notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
2198      normal: {
2199        title: '围栏通知',
2200        text: '围栏退出',
2201        additionalText: ""
2202      }
2203    }
2204  };
2205  // 把创建的通知对象存入Array中,存入顺序与transitionStatusList一致
2206  let notificationRequestList: Array<notificationManager.NotificationRequest> =
2207    [notificationRequest1, notificationRequest2];
2208  // 构造GNSS地理围栏请求对象gnssGeofenceRequest
2209  let gnssGeofenceRequest: geoLocationManager.GnssGeofenceRequest = {
2210    // 围栏属性,包含圆心和半径等信息
2211    geofence: geofence,
2212    // 指定APP需要监听的地理围栏事件类型
2213    monitorTransitionEvents: transitionStatusList,
2214    // 地理围栏事件对应的通知对象,该参数为可选
2215    notifications: notificationRequestList,
2216    // 用于监听围栏事件的callback
2217    geofenceTransitionCallback: (err : BusinessError, transition : geoLocationManager.GeofenceTransition) => {
2218      if (err) {
2219        console.error('geofenceTransitionCallback: err=' + JSON.stringify(err));
2220      }
2221      if (transition) {
2222        console.info("GeofenceTransition: %{public}s", JSON.stringify(transition));
2223    }
2224    }
2225  }
2226  try {
2227    // 添加围栏
2228    geoLocationManager.addGnssGeofence(gnssGeofenceRequest).then((id) => {
2229      // 围栏添加成功后返回围栏ID
2230      console.info("addGnssGeofence success, fence id: " + id);
2231      let fenceId = id;
2232    }).catch((err: BusinessError) => {
2233      console.error("addGnssGeofence failed, promise errCode:" + (err as BusinessError).code +
2234        ",errMessage:" + (err as BusinessError).message);
2235    });
2236  } catch(error) {
2237      console.error("addGnssGeofence failed, err:" + JSON.stringify(error));
2238  }
2239  ```
2240
2241
2242## geoLocationManager.removeGnssGeofence<sup>12+</sup>
2243
2244removeGnssGeofence(geofenceId: number): Promise&lt;void&gt;
2245
2246删除一个GNSS地理围栏,并取消订阅该地理围栏事件。使用Promise异步回调。
2247
2248GNSS地理围栏功能依赖GNSS定位芯片(仅部分型号支持),如果设备无此芯片或使用的芯片型号不支持该功能,则返回错误码801(Capability not supported)。
2249
2250**需要权限**:ohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
2251
2252**系统能力**:SystemCapability.Location.Location.Geofence
2253
2254**参数**:
2255
2256  | 参数名 | 类型 | 必填 | 说明 |
2257  | -------- | -------- | -------- | -------- |
2258  | geofenceId | number | 是 | GNSS地理围栏的ID。 |
2259
2260**返回值**:
2261
2262  | 类型 | 说明 |
2263  | -------- | -------- |
2264  | Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
2265
2266**错误码**:
2267
2268以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2269
2270| 错误码ID | 错误信息 |
2271| -------- | ---------------------------------------- |
2272|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
2273|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.                 |
2274|801 | Capability not supported. Failed to call ${geoLocationManager.removeGnssGeofence} due to limited device capabilities.          |
2275|3301000 | The location service is unavailable. |
2276|3301602 | Failed to delete a geofence due to an incorrect ID. |
2277
2278**示例**
2279
2280  ```ts
2281  import { geoLocationManager } from '@kit.LocationKit';
2282  import { BusinessError } from '@kit.BasicServicesKit';
2283  // fenceId是在geoLocationManager.addGnssGeofence执行成功后获取的
2284  let fenceId = 1;
2285  try {
2286    geoLocationManager.removeGnssGeofence(fenceId).then(() => {
2287      console.info("removeGnssGeofence success fenceId:" + fenceId);
2288    }).catch((error : BusinessError) => {
2289      console.error("removeGnssGeofence: error=" + JSON.stringify(error));
2290    });
2291  } catch(error) {
2292    console.error("removeGnssGeofence: error=" + JSON.stringify(error));
2293  }
2294  ```
2295
2296
2297## geoLocationManager.getGeofenceSupportedCoordTypes<sup>12+</sup>
2298
2299getGeofenceSupportedCoordTypes(): Array&lt;CoordinateSystemType&gt;
2300
2301获取地理围栏功能支持的坐标系列表。
2302
2303**系统能力**:SystemCapability.Location.Location.Geofence
2304
2305**返回值**:
2306
2307  | 类型 | 说明 |
2308  | -------- | -------- |
2309  | Array&lt;[CoordinateSystemType](#coordinatesystemtype12)&gt; | 地理围栏功能支持的坐标系列表。 |
2310
2311**错误码**:
2312
2313以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2314
2315| 错误码ID | 错误信息 |
2316| -------- | ---------------------------------------- |
2317|801 | Capability not supported. Failed to call ${geoLocationManager.getGeofenceSupportedCoordTypes} due to limited device capabilities.          |
2318|3301000 | The location service is unavailable. |
2319
2320**示例**
2321
2322  ```ts
2323  import { geoLocationManager } from '@kit.LocationKit';
2324  try {
2325    let supportedCoordTypes: Array<geoLocationManager.CoordinateSystemType> = geoLocationManager.getGeofenceSupportedCoordTypes();
2326    console.info("getGeofenceSupportedCoordTypes return:" + JSON.stringify(supportedCoordTypes));
2327  } catch(error) {
2328    console.error("getGeofenceSupportedCoordTypes: error=" + JSON.stringify(error));
2329  }
2330  ```
2331
2332
2333## geoLocationManager.getCurrentWifiBssidForLocating<sup>14+</sup>
2334
2335getCurrentWifiBssidForLocating(): string
2336
2337获取连接的Wi-Fi AP(Access Point)的Bssid(Basic Service Set Identifier)信息
2338
2339**需要权限**:ohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
2340
2341**系统能力**:SystemCapability.Location.Location.Core
2342
2343**返回值**:
2344
2345  | 类型 | 说明 |
2346  | -------- | -------- |
2347  | string | Wi-Fi Bssid |
2348
2349**错误码**:
2350
2351以下错误码的详细介绍请参见[位置服务子系统错误码](errorcode-geoLocationManager.md)。
2352
2353| 错误码ID | 错误信息 |
2354| -------- | ---------------------------------------- |
2355|201 | Permission verification failed. The application does not have the permission required to call the API.                 |
2356|801 | Capability not supported. Failed to call ${geoLocationManager.getCurrentWifiBssidForLocating()} due to limited device capabilities.          |
2357|3301000 | The location service is unavailable.                                           |
2358|3301100 | The location switch is off.                                                 |
2359|3301900 | Failed to obtain the BSSID of the Wi-Fi hotspot. The Wi-Fi network is not connected. |
2360
2361**示例**
2362
2363  ```ts
2364  import { geoLocationManager } from '@kit.LocationKit';
2365  try {
2366    let bssid: string = geoLocationManager.getCurrentWifiBssidForLocating();
2367    console.info("get wifi bssid:" + bssid);
2368  } catch(error) {
2369    console.error("getCurrentWifiBssidForLocating: errCode" + error.code + ", errMessage" + error.message);
2370  }
2371  ```