HarmonyOS geoLocationManager.getAddressesFromLocation将坐标转换为地理描述报错“{code":3301300,"message":"BussinessError 3301300: Reverse geocoding query failed."}”

Button('转化地理位置')
  .onClick(async () => {
    console.log('进来')
    // console.log('simplt', this.simplt)
    try {
      let reverseGeocodeRequest: geoLocationManager.ReverseGeoCodeRequest =
        { "latitude": 31.12, "longitude": 121.11, "maxItems": 1 };
      //转化坐标为具体的地址描述
      let addressFromLocation = await geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest)
      console.log('getAddressesFromLocation',JSON.stringify(addressFromLocation))

    }
    catch(err){
      console.log(JSON.stringify(err))
    }
  })
})
HarmonyOS
3天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

获取位置的时候:

1.请确认下是否有配置权限module.json5中权限是否配置。

2.代码中是否已经授权打开位置获取。

3.模拟器中获取不了位置信息,请用样机测试。

可以参考demo:

// xxx.ets
import { abilityAccessCtrl, common, Permissions } from '@kit.AbilityKit';
import { geoLocationManager } from '@kit.LocationKit';

@Entry
@Component
struct Index {
  @State localText: string = '当前位置'
  permissions: Array<Permissions> = ['ohos.permission.APPROXIMATELY_LOCATION', 'ohos.permission.LOCATION'];
  getLocal() {
    const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
    let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
    // requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗
    atManager.requestPermissionsFromUser(context, this.permissions).then((data) => {
      let grantStatus: Array<number> = data.authResults;
      let length: number = grantStatus.length;
      for (let i = 0; i < length; i++) {
        if (grantStatus[i] === 0) {
          // 用户授权,可以继续访问目标操作
          const requestInfo: geoLocationManager.LocationRequest = {
            'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX,
            'scenario': geoLocationManager.LocationRequestScenario.UNSET,
            'timeInterval': 1,
            'distanceInterval': 0,
            'maxAccuracy': 0
          };
          geoLocationManager.getCurrentLocation(requestInfo)
            .then((location: geoLocationManager.Location) => {
              let reverseGeocodeRequest: geoLocationManager.ReverseGeoCodeRequest = location;
              try {
                geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
                  console.log('getAddressesFromLocation: ' + JSON.stringify(data));
                  this.localText = data[0].placeName + ''
                })
                  .catch((error: number) => {
                    console.error('promise, getAddressesFromLocation: error=' + JSON.stringify(error));
                  });
              } catch (err) {
                console.error("errCode:");
              }
            })
            .catch((err: Error) => {
              console.error(`Failed to get current location. Code is , message is ${err.message}`);
            });
        } else {
          // 用户拒绝授权
          return;
        }
      }
      // 授权成功
    }).catch((err: Error) => {
      console.error(`Failed to request permissions from user. Code is , message is ${err.message}`);
    })
  }
  build() {
    Column() {
      Button(this.localText).onClick(() => {
        this.getLocal();
      })
    }
  }
}
分享
微博
QQ
微信
回复
3天前
相关问题
HarmonyOS 如何视频转换为GIF
32浏览 • 1回复 待解决
HarmonyOS 怎么日期转换为星期几
45浏览 • 1回复 待解决
ERROR: Schema validate failed.
740浏览 • 1回复 待解决
Error: Install eTS 3.1.0.0 failed.
3953浏览 • 1回复 待解决
HarmonyOS 如何base64数据转换为图片
554浏览 • 1回复 待解决