| | |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | |
| | | import publicway.Gpstoxuzuobiao; |
| | | |
| | | public class Control02 { |
| | | |
| | | /** |
| | |
| | | * 例如:3949.90238860 -> 39.83170647666667 |
| | | */ |
| | | private static double parseDMToDecimal(String dmm, String direction) { |
| | | try { |
| | | // 找到小数点的位置 |
| | | int dotIndex = dmm.indexOf('.'); |
| | | if (dotIndex < 2) { |
| | | throw new IllegalArgumentException("度分格式错误: " + dmm); |
| | | } |
| | | |
| | | // 提取度和分 |
| | | int degrees = Integer.parseInt(dmm.substring(0, dotIndex - 2)); |
| | | double minutes = Double.parseDouble(dmm.substring(dotIndex - 2)); |
| | | |
| | | // 转换为十进制 |
| | | double decimal = degrees + minutes / 60.0; |
| | | |
| | | // 根据方向调整正负 |
| | | if ("S".equalsIgnoreCase(direction) || "W".equalsIgnoreCase(direction)) { |
| | | decimal = -decimal; |
| | | } |
| | | |
| | | return decimal; |
| | | } catch (Exception e) { |
| | | throw new IllegalArgumentException("坐标格式解析错误: " + dmm, e); |
| | | } |
| | | return Gpstoxuzuobiao.parseDMToDecimal(dmm, direction); |
| | | } |
| | | |
| | | private static String bytesToHex(byte[] bytes) { |