HarmonyOS 定位失败 错误码3301200:?

定位经常失败,尤其是第一次安装APP的时候,十次有3次都是失败,有没有什么优化方式,超时的时间也很长

{“code”:3301200,“message”:“BussinessError 3301200: Failed to obtain the geographical location.”}

let requestInfo:geoLocationManager.CurrentLocationRequest = { 'priority': geoLocationManager.LocationRequestPriority.LOW_POWER, 'maxAccuracy': 4 };
阅读 593
1 个回答

定位失败的原因主要是因为 maxAccuracy 设置的太小了,导致定位坐标被认定为不符合要求而被忽略,可以尝试改大一些,比如 100,经测试第一次定位 1s左右,后面每次都是几十毫秒

let startTime = new Date().getTime();
let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX,
  'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 100};

let locationChange = (err:BusinessError, location:geoLocationManager.Location):void => {
  if (err) {
    console.error('locationChanger: err=' + JSON.stringify(err));
  }
  if (location) {
    console.log('locationChanger: location=' + JSON.stringify(location));
    this.message = '定位信息:' + JSON.stringify(location) + '\n 花费时间:' + (new Date().getTime() - startTime) / 1000
  }
};
try {
  geoLocationManager.getCurrentLocation(requestInfo, locationChange);
} catch (err) {
  console.error("errCode:" + err.code + ",errMessage:" + err.message);
};
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进