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