HarmonyOS 在设置,隐私和安全,关闭定位后 geoLocationManager.getCurrentLocation没有回调

在设置,隐私和安全,关闭定位后 geoLocationManager.getCurrentLocation没有回调

传参如下:

{
  'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, //表示快速获取位置优先,如果应用希望快速拿到一个位置,可以将优先级设置为该字段。
'scenario': geoLocationManager.LocationRequestScenario.UNSET, //表示未设置优先级,表示LocationRequestPriority无效。
'timeInterval': 10, //表示上报位置信息的时间间隔,单位是秒。默认值为1,取值范围为大于等于0。10秒钟获取一下位置
'distanceInterval': 0, //表示上报位置信息的距离间隔。单位是米,默认值为0,取值范围为大于等于0。
'maxAccuracy': 0 //表示精度信息,单位是米。
}
HarmonyOS
2025-01-10 09:10:51
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

在位置服务关闭后,geoLocationManager.getCurrentLocation 是无法正常调用的,需要做 try catch 处理,才能捕捉到报错信息,示例如下:

static getCurrentLocationEasy(callBack: Callback<geoLocationManager.Location>) {
  try {
    geoLocationManager.getCurrentLocation(LocationUtil.currentRequest, (error: BusinessError, location: geoLocationManager.Location): void => {
      if (error) {

      }
      if (location && callBack) {
        callBack(location)
      }
    });
  } catch (err) {
    console.error("errCode:" + JSON.stringify(err));
  }
}

报错信息:errCode:{“code”:“3301100”};表示 The location switch is off.

详细信息请参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-geolocationmanager-V5#geolocationmanagergetcurrentlocation-1

分享
微博
QQ
微信
回复
2025-01-10 10:58:53
相关问题
HarmonyOS 登录组件点击隐私没有
280浏览 • 1回复 待解决
支付成功没有收到
2196浏览 • 1回复 待解决
HarmonyOS Watch没有
396浏览 • 1回复 待解决
HarmonyOS @Watch方法没有改变
354浏览 • 1回复 待解决
隐私安全页面跳转实践
3288浏览 • 1回复 待解决