zoukankan      html  css  js  c++  java
  • Android 得到照片位置信息

    目前Android SDK定义的Tag有:
    TAG_DATETIME    时间日期
    TAG_FLASH   闪光灯
    TAG_GPS_LATITUDE   纬度
    TAG_GPS_LATITUDE_REF  纬度参考
    TAG_GPS_LONGITUDE   经度
    TAG_GPS_LONGITUDE_REF  经度参考
    TAG_IMAGE_LENGTH   图片长
    TAG_IMAGE_WIDTH   图片宽
    TAG_MAKE   设备制造商
    TAG_MODEL   设备型号
    TAG_ORIENTATION   方向
    TAG_WHITE_BALANCE   白平衡

    String sFileName="/sdcard/DCIM/Camera/1.JPG";
    try{
          ExifInterface exif = new ExifInterface(sFileName);
          String sModel=exif.getAttribute(ExifInterface.TAG_MODEL);
          Toast.makeText(PhotoCatActivity.this,"1.JPG Exif:"+sModel, Toast.LENGTH_SHORT).show();
    } catch(Exception ee){
         
    }

    经纬度得到的数据格式是 "num1/denom1,num2/denom2,num3/denom3",如何得到真正的经纬度呢?

    public Location exif2Loc(String flNm) {
      String sLat = "", sLatR = "", sLon = "", sLonR = "";
      try {
        ExifInterface ef = new ExifInterface(flNm);
        sLat  = ef.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
        sLon  = ef.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
        sLatR = ef.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
        sLonR = ef.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
      } catch (IOException e) {return null;}
    
      double lat = dms2Dbl(sLat);
      if (lat > 180.0) return null;
      double lon = dms2Dbl(sLon);
      if (lon > 180.0) return null;
    
      lat = sLatR.contains("S") ? -lat : lat;
      lon = sLonR.contains("W") ? -lon : lon;
    
      Location loc = new Location("exif");
      loc.setLatitude(lat);
      loc.setLongitude(lon);
      return loc;
    }
    
    
    //-------------------------------------------------------------------------
    double dms2Dbl(String sDMS){
      double dRV = 999.0;
      try {
        String[] DMSs = sDMS.split(",", 3);
        String s[] = DMSs[0].split("/", 2);
        dRV = (new Double(s[0])/new Double(s[1]));
        s = DMSs[1].split("/", 2);
        dRV += ((new Double(s[0])/new Double(s[1]))/60);
        s = DMSs[2].split("/", 2);
        dRV += ((new Double(s[0])/new Double(s[1]))/3600);
      } catch (Exception e) {}
      return dRV;
    }

    如何根据经纬度得到具体的地址?

    public final String getAddress(double latitude, double longitude) {
      Geocoder gc = new Geocoder(this, Locale.getDefault());
      StringBuilder sb = new StringBuilder();
      try {
       List
    
    add = gc.getFromLocation(latitude, longitude, 1);
       if (add.size() > 0) {
        Address ad = add.get(0);
        sb.append(ad.getAddressLine(0));
        sb.append(ad.getAddressLine(1));
        sb.append(ad.getAddressLine(2));
       }
      } catch (Exception e) {
    
    
      }
      return sb.toString();
     }
  • 相关阅读:
    ffmpeg mp4 视频输出为 aac 的命令
    git操作远程分支
    Linux (openSUSE 15.3 ) server ssh 可以使用,sftp无法使用
    小小思考题
    Linux 命令介绍
    2021 年 如何使用VMware 安装 ubuntu 7.04 虚拟机, 配置 apt 源
    Linux 下 命令行 使用浏览器
    oracle.cmd
    Sqlcmd
    vue eslint 配置使用
  • 原文地址:https://www.cnblogs.com/netcorner/p/7279984.html
Copyright © 2011-2022 走看看