将纬度和经度值(度)转换为Double.Java的

Bor*_*ora 1 java android

我正在尝试将度数的纬度和经度值转换为double.价值是这样的

 "latitude":"25°21 N",
        "longitude":"55°23 E"
Run Code Online (Sandbox Code Playgroud)

当我尝试在Android中记录它时,它就像这样. 在此输入图像描述

"A^"那里有什么特别的炭.怎么来的 此外,当我尝试保存日志时,它就像 25°21 N

如何将度数值转换为纬度和经度的两倍?

谢谢

Ram*_*oza 5

对于您当前的示例,您必须解析输入,一次解析分配给该公式.

解析输入

Map<String,String> yourMap; //imagine is your input 
                            //"latitude":"25°21 N",
                            //"longitude":"55°23 E"

String latitude = yourMap.get("latitude");
String hour = latitude.split("º")[0];
String minute = latitude.split("º")[1].split(" ")[0];

// This is a very ugly way to parse it, better do with regular expressions, 
// but I'm not an expert on them and cannot figure them.


//Parse result
String hour = "25";
String minute = "21";
String second = "0";

//Formula
double result = Integer.intValue(hour) + 
                Integer.intValue(minute) / 60 + 
                Integer.intValue(second) / 3600;
Run Code Online (Sandbox Code Playgroud)