HarmonyOS 获取当前定位不准确

​获取当前定位不准确,差距特别大

当前位置为余杭区高教路 970 号,以下配置不同的 priority 都存在较大的定位差距

requestInfo 参数中的

priority 设置成 FIRST_FIX

scenario 设置成 UNSET

getCurrentLocation 方法 能获取到 经纬度,而且获取的经纬度,不准确,差距 特别大(跨区)

priority 设置成 ACCURACY

scenario 设置成 DAILY_LIFE_SERVICE

getCurrentLocation 能获取到 经纬度,而且获取的经纬度,不准确,差距 特别大(跨区)

若是将

priority 设置成 ACCURACY

scenario 设置成 NAVIGATION

getCurrentLocation 方法获取不到经纬度,并报 3301200 Failed to obtain the geographical location 错误。​

import geoLocationManager from '@ohos.geoLocationManager'; 
 
let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0}; 
 
geoLocationManager.getCurrentLocation(requestInfo, (err,location) => { 
  // 使用  逆地址 编码进行解析 
  let reverseGeocodeReq:geoLocationManager.ReverseGeoCodeRequest = {'latitude':location.latitude,'longitude':location.longitude,'maxItems':1} 
  geoLocationManager.getAddressesFromLocation(reverseGeocodeReq,(err, resultValues) => { 
    console.log('location getAddressesFromLocation = '+JSON.stringify(resultValues)) 
  }) 
 
  ))
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
HarmonyOS
2024-11-11 10:47:00
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

验证问题后,发现第一种和第二种情况并未出现所说的存在较大的定位差距,第三种情况priority 设置成 ACCURACY,scenario 设置成 NAVIGATION,使用的均是GNSS定位技术,在室内、车库等遮蔽环境,GNSS技术很难提供定位服务。参考代码如下:

import geoLocationManager from '@ohos.geoLocationManager'; 
import BusinessError from "@ohos.base"; 
import abilityAccessCtrl from "@ohos.abilityAccessCtrl"; 
 
@Entry 
@Component 
export struct Location { 
  atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager() 
  build() { 
    Column() { 
      // 在module.json5里申明ohos.permission.LOCATION,ohos.permission.APPROXIMATELY_LOCATION权限 
      Button('获取当前定位授权') 
        .onClick(() => { 
          const context = getContext() 
          this.atManager.requestPermissionsFromUser(context, ['ohos.permission.LOCATION','ohos.permission.APPROXIMATELY_LOCATION'], (err, data) => { 
            data.authResults.forEach(item => { 
              if (item === 0) { 
                console.log(`wsf: 权限申请成功`); 
              } else { 
                console.log(`wsf: 权限申请失败`); 
              } 
            }) 
          }) 
        }) 
 
      Button('判断定位位置是否使能') 
        .onClick(() => { 
          try { 
            let locationEnabled = geoLocationManager.isLocationEnabled(); 
            console.log(`wsf: locationEnabled = ${locationEnabled}`) 
          } catch (err) { 
            console.error("wsf: errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 
          } 
        }) 
 
      Button('获取当前定位') 
        .onClick(() => { 
          let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.ACCURACY, 'scenario': geoLocationManager.LocationRequestScenario.NAVIGATION,'maxAccuracy': 0}; 
          try { 
            geoLocationManager.getCurrentLocation(requestInfo).then((location) => { 
              // 使用 逆地址 编码进行解析 
              let reverseGeocodeReq: geoLocationManager.ReverseGeoCodeRequest = { 
                'latitude': location.latitude, 
                'longitude': location.longitude, 
                'maxItems': 1 
              } 
              geoLocationManager.getAddressesFromLocation(reverseGeocodeReq, (err, resultValues) => { 
                console.log('location getAddressesFromLocation = ' + JSON.stringify(resultValues)) 
              }) 
            }) 
              .catch((error:number) => { 
                console.error('wsf: promise, getCurrentLocation: error=' + JSON.stringify(error)); 
              }); 
          } catch (err) { 
            console.error("wsf: errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); 
          } 
        }) 
    } 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
分享
微博
QQ
微信
回复
2024-11-11 15:14:16
相关问题
求告知如何获取当前定位
1165浏览 • 1回复 待解决
HarmonyOS 获取网络的信息不准确
895浏览 • 1回复 待解决
Polyline组件绘制坐标不准确
2892浏览 • 1回复 待解决
HarmonyOS 卡片定时刷新时间不准确
706浏览 • 1回复 待解决
HarmonyOS onScroll回调yoffset不准确问题
1335浏览 • 1回复 待解决
HarmonyOS List停止滑动回调不准确
1322浏览 • 1回复 待解决
HarmonyOS uv timer定时器不准确
1336浏览 • 1回复 待解决
mysql LEFT JOIN 使用SUM不准确
3640浏览 • 1回复 待解决
HarmonyOS 地图的路径规划功能不准确
1024浏览 • 1回复 待解决
地图定位不准,是什么原因啊?
832浏览 • 1回复 待解决
卡片的ID怎么准确获取
204浏览 • 0回复 待解决