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