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