如何从android中的纬度值中找到度数?

Pra*_*een 5 java android location

我将纬度和经度值作为双精度值(37.33168900,-122.03073100).

我想将它转换为度数值(37 19'54,48 11'52).

任何的想法?Thanx提前.

Nic*_*ckT 12

这将为您提供弧度,分钟和秒的字符串:

String strLongitude = location.convert(location.getLongitude(), location.FORMAT_SECONDS);
String strLatitude = location.convert(location.getLatitude(), location.FORMAT_SECONDS);
Run Code Online (Sandbox Code Playgroud)

.


abi*_*abi 8

用这个

public static String getFormattedLocationInDegree(double latitude, double longitude) {
    try {
        int latSeconds = (int) Math.round(latitude * 3600);
        int latDegrees = latSeconds / 3600;
        latSeconds = Math.abs(latSeconds % 3600);
        int latMinutes = latSeconds / 60;
        latSeconds %= 60;

        int longSeconds = (int) Math.round(longitude * 3600);
        int longDegrees = longSeconds / 3600;
        longSeconds = Math.abs(longSeconds % 3600);
        int longMinutes = longSeconds / 60;
        longSeconds %= 60;
        String latDegree = latDegrees >= 0 ? "N" : "S";
        String lonDegrees = longDegrees >= 0 ? "E" : "W";

        return  Math.abs(latDegrees) + "°" + latMinutes + "'" + latSeconds
                + "\"" + latDegree +" "+ Math.abs(longDegrees) + "°" + longMinutes
                + "'" + longSeconds + "\"" + lonDegrees;
    } catch (Exception e) {
        return ""+ String.format("%8.5f", latitude) + "  "
                + String.format("%8.5f", longitude) ;
    }
}
Run Code Online (Sandbox Code Playgroud)


Chr*_*ach 7

应该是一些数学:

(int)37.33168                => 37
37.33168 % 1 = 0.33168       
0.33168 * 60 = 19,905        => 19
19.905 % 1 = 0.905
0.905 * 60                   => 54
Run Code Online (Sandbox Code Playgroud)

与-122相同(如果是负值则添加360)

编辑: 可能有一些API,我不知道.