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