将经度和纬度值(度)转换为双精度。 Java

问题描述:

我正在尝试将纬度和经度值以度数加倍。 值都是这样将经度和纬度值(度)转换为双精度。 Java

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

当我尝试在Android中它是未来类似这样的记录本。 enter image description here

这是什么"A^"特殊字符那里。它是如何来的。另外当我尝试保存日志 它就像25°21 N

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

感谢

+0

的你真正想要做将有助于一些示例代码。 –

+0

@AleksanderLidtke我只是记录纬度值和获取额外的字符在查看使用ddms logcat – Bora

您当前的例子,你要分析你的输入,一个时间它被解析分配给该公式。

解析输入

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; 
+0

是的,谢谢,在此之前,我有情况来解析我得到的字符串。 – Bora

+0

我得到像25°21 N的字符串,当我尝试记录它时,显示出一些特殊的字符。它是如何来的? – Bora

+0

更新了答案,告诉你,一个丑陋的方法来解析你的字符串 – RamonBoza