我有一个位置格式 (24°13'30.92"N,55°45'51.94"E),我需要通过 android 将其转换为 double 值,例如 (24.225275, 55.764417)。
我试过类似的方法,但没有用
String lonStr="24°13'30.92"N";
Double lon=Location.convert(lonStr);
最佳答案
Use
substring
andindexOf
extract minutes and second divide by 60 and 3600 respectively and finally add degree part.
String str="24°13'30.92\"N,55°45'51.94\"E";
String s[]=str.split(",");
double lat=Integer.parseInt(s[0].substring(0,s[0].indexOf("°")))+(double)Integer.parseInt(s[0].substring(s[0].indexOf("°")+1, s[0].indexOf("'")))/60+ Double.parseDouble(s[0].substring(s[0].indexOf("'")+1, s[0].indexOf("\"")))/3600;
// same for longitude
System.out.println(String.format("%.6f", lat));
输出:
24.225256
关于Android 位置将纬度和经度从 DMS 格式更改为 double ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33096284/