Convert Latitude and Longitude Values (Degrees) to Double . Java

后端 未结 1 367
梦谈多话
梦谈多话 2021-01-24 23:38

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\"         


        
相关标签:
1条回答
  • 2021-01-25 00:09

    for your current example, you have to parse your input, one time it is parsed assign to that formula.

    Parsing the input

    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 讨论(0)
提交回复
热议问题