有没有办法将我的终点方向转换为数字?

问题描述

因此,当我尝试将结束方向(例如N,S,E,W)转换为正1.0或负1.0以乘以最终的度/分钟的秒数时,我的 double 符号始终返回0.0。我尝试在单独的 if 语句中测试每个字母,并尝试将计算结果放入 if 语句。

我一直在测试以下坐标: 40°35'6.9288“北

public static double convertDegreesToDecimals(String strValue) {
   double decimal = 0;
   double sign = 1.0;

   String degree = strValue.substring(0,strValue.indexOf(DEGREE));
   double deg = Double.parseDouble(degree);
   String minute = strValue.substring(strValue.indexOf(DEGREE)+1,strValue.indexOf(MINUTE));
   double min = Double.parseDouble(minute);
   String second = strValue.substring(strValue.indexOf(MINUTE)+1,strValue.indexOf(SECOND));
   double sec = Double.parseDouble(second);
   String direction = strValue.substring(strValue.indexOf(SECOND)+1,strValue.length());
   System.out.println(direction);   //prints N,S,or whatever the direction is correctly
  
   if(direction=="S" || direction=="E"){
      double sign = -1.0;
   }else if(direction=="N" || direction=="W"){
      double sign = 1.0;
   }
  
   decimal = ( (deg + (min / 60.0) + (sec / 3600.0) ) * sign);
   return decimal;
}

我希望 double 符号在方向为S或W时等于-1.0,在方向为N或E时等于1.0。我计算的度/分的秒数为正确的除符号外,字符串方向总是返回预期结果(N,S,E,W)。当我在 if println 语句时, / strong>语句,它们没有执行,这使我认为 if 语句一定有问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...