1

I am trying to convert latitude and longitude values which are in degrees to double. the values are like this

 "latitude":"25°21 N",
        "longitude":"55°23 E"

When i try to log this in android it is coming like this. enter image description here

What is this "A^" special char there . How it came. Also when i try to save the log it was like 25°21 N

How to convert the degree values to double for latitude and longitude ?

Thanks

4

1 回答 1

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;
于 2013-10-17T10:00:31.903 回答