Android扫描存储图片获取经纬度并转换

1、获取值

    public static ArrayList<String> readPictureLocation(String path, String lat, String lon) {
        ArrayList<String> result = new ArrayList<>();
        try {
            ExifInterface exifInterface = new ExifInterface(path);
            String la = readLoc(exifInterface.getAttribute(ExifInterface.TAG_GPS_LATITUDE));
            String lo = readLoc(exifInterface.getAttribute(ExifInterface.TAG_GPS_LONGITUDE));
            if (TextUtils.isEmpty(la) || TextUtils.isEmpty(lo)) {
                la = lat;
                lo = lon;
            }
            result.add(la);
            result.add(lo);
            String time = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
            if (TextUtils.isEmpty(time)) {
                time = TimeUtils.getCurrentTime2();
            }
            result.add(time);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

2、转换度分秒格式值

获取示例:55/1,66/1,777/100

    public static String readLoc(String loc) {
        if (TextUtils.isEmpty(loc) || !loc.contains("/") || !loc.contains(","))
            return null;
        try {
            double d = Double.parseDouble(loc.split("/")[0]);
            double m = Double.parseDouble(loc.split(",")[1].split("/")[0]);
            double s = Double.parseDouble(loc.split(",")[2].split("/")[0]);
            return String.valueOf(((s / 100) / 60 + m) / 60 + d);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

你可能感兴趣的:(Kotlin,Flutter,AS,前端,android,java,开发语言)