HarmonyOS 如何获取相册里照片的地理位置信息

  1. 试了相机拍照, 查看图库照片详情,没有显示出拍摄地点
  2. 自己拍摄的图片, 查看文档 PHOTO_KEY 枚举类型里面无地理位置信息关键字

是否有方法支持获取图片位置信息

HarmonyOS
14h前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

请确认拍照时开启了网络和定位,参考如下代码获取:通过picker获取图片uri:

// 调用PhotoViewPicker.select选择图片
async function photoPickerGetUri() {
  try {

    PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;
    PhotoSelectOptions.maxSelectNumber = 15;
    // PhotoSelectOptions.isEditSupported=true;
    let photoPicker = new photoAccessHelper.PhotoViewPicker();
    photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => {
      console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult));
      uris = PhotoSelectResult.photoUris;
      // photoPicker.preSelectUris=uris;
      PhotoSelectOptions.preselectedUris=uris;
      console.info('photoViewPicker.select to file succeed and uris are:' + uris);
    }).catch((err: BusinessError) => {
      console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err));
    });
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
  }
}
//根据uri创建imagegesource,获取ImageProperty属性:
async pixelMap(){
  let file = fs.openSync(uris[0], fs.OpenMode.READ_ONLY);
  console.info(`TestAlbum asset: uri=${uris[0]}`)

  console.info('file fd: ' + file.fd);
  //根据文件fd创建imagSource
  const imageSource: image.ImageSource = image.createImageSource(file.fd);
  let options: image.ImagePropertyOptions = { index: 0, defaultValue: '0' }
  //完成后关闭fd
  fs.closeSync(file);
  const latitude: string = await imageSource.getImageProperty(image.PropertyKey.GPS_LATITUDE, options);
  const longitude: string = await imageSource.getImageProperty(image.PropertyKey.GPS_LONGITUDE, options);
  const ooo: string = await imageSource.getImageProperty(image.PropertyKey.ORIENTATION, options);
  const ImageDescription: string =
    await imageSource.getImageProperty(image.PropertyKey.IMAGE_DESCRIPTION, options);
  console.info(`TestAlbum asset: uri=${uris[0]}, latitude=${latitude}, longitude=${longitude}},ooooo=${ooo}`)
  console.info('TestAlbum asset ' + ImageDescription);
}
分享
微博
QQ
微信
回复
11h前
相关问题
获取安全地理位置信息接口实现
383浏览 • 1回复 待解决
MySQL 如何按照地理位置排序?
2737浏览 • 1回复 待解决
如何在har中获取hap中置信息
274浏览 • 1回复 待解决
app.getInfo获取应用配置信息为空。
679浏览 • 1回复 待解决