@Test public void parseLongitudeLatitude() { assertThat(LocationUtil.parseDegrees("29º40'N"), is(29.0 + 40.0 / 60.0)); assertThat(LocationUtil.parseDegrees("85º10'W"), is(-(85.0 + 10.0 / 60.0))); Double actual = LocationUtil.parseDegrees("85º10'11''E"); assertThat(String.format("%.2f", actual), is(String.format("%.2f", (85.0 + 10.0 / 60.0 + 11.0 / 3600.0)))); Double actual1 = LocationUtil.parseDegrees("29º40'01''S"); assertThat(String.format("%.2f", actual1), is(String.format("%.2f", -(29.0 + 40.0 / 60.0 + 1.0 / 3600.0)))); }
public static Double parseDegrees(String latString) { String[] split = latString.split("º"); if (split.length == 1) { split = latString.split("�"); } if (split.length == 1) { split = latString.split("°"); } Double degrees = 0.0; Double minutes = 0.0; Double seconds = 0.0; if (split.length > 1) { degrees = Double.parseDouble(split[0]); split = split[1].split("'"); if (split.length > 1) { minutes = Double.parseDouble(split[0]); split = split[1].split("''"); if (split.length > 1) { seconds = Double.parseDouble(split[0]); } } } Double lat = degrees + minutes / 60.0 + seconds / 3600.0; lat = lat * (latString.endsWith("N") || latString.endsWith("E") ? 1.0 : -1.0); return lat; }
LocationUtil { public static Double parseDegrees(String latString) { String[] split = latString.split("º"); if (split.length == 1) { split = latString.split("�"); } if (split.length == 1) { split = latString.split("°"); } Double degrees = 0.0; Double minutes = 0.0; Double seconds = 0.0; if (split.length > 1) { degrees = Double.parseDouble(split[0]); split = split[1].split("'"); if (split.length > 1) { minutes = Double.parseDouble(split[0]); split = split[1].split("''"); if (split.length > 1) { seconds = Double.parseDouble(split[0]); } } } Double lat = degrees + minutes / 60.0 + seconds / 3600.0; lat = lat * (latString.endsWith("N") || latString.endsWith("E") ? 1.0 : -1.0); return lat; } }
LocationUtil { public static Double parseDegrees(String latString) { String[] split = latString.split("º"); if (split.length == 1) { split = latString.split("�"); } if (split.length == 1) { split = latString.split("°"); } Double degrees = 0.0; Double minutes = 0.0; Double seconds = 0.0; if (split.length > 1) { degrees = Double.parseDouble(split[0]); split = split[1].split("'"); if (split.length > 1) { minutes = Double.parseDouble(split[0]); split = split[1].split("''"); if (split.length > 1) { seconds = Double.parseDouble(split[0]); } } } Double lat = degrees + minutes / 60.0 + seconds / 3600.0; lat = lat * (latString.endsWith("N") || latString.endsWith("E") ? 1.0 : -1.0); return lat; }  }
LocationUtil { public static Double parseDegrees(String latString) { String[] split = latString.split("º"); if (split.length == 1) { split = latString.split("�"); } if (split.length == 1) { split = latString.split("°"); } Double degrees = 0.0; Double minutes = 0.0; Double seconds = 0.0; if (split.length > 1) { degrees = Double.parseDouble(split[0]); split = split[1].split("'"); if (split.length > 1) { minutes = Double.parseDouble(split[0]); split = split[1].split("''"); if (split.length > 1) { seconds = Double.parseDouble(split[0]); } } } Double lat = degrees + minutes / 60.0 + seconds / 3600.0; lat = lat * (latString.endsWith("N") || latString.endsWith("E") ? 1.0 : -1.0); return lat; }  static Double parseDegrees(String latString); static boolean isValidLongitude(Double longitude); static boolean isValidLatitude(Double latitude); static LatLng parseLatLng(String latitude, String longitude); }
LocationUtil { public static Double parseDegrees(String latString) { String[] split = latString.split("º"); if (split.length == 1) { split = latString.split("�"); } if (split.length == 1) { split = latString.split("°"); } Double degrees = 0.0; Double minutes = 0.0; Double seconds = 0.0; if (split.length > 1) { degrees = Double.parseDouble(split[0]); split = split[1].split("'"); if (split.length > 1) { minutes = Double.parseDouble(split[0]); split = split[1].split("''"); if (split.length > 1) { seconds = Double.parseDouble(split[0]); } } } Double lat = degrees + minutes / 60.0 + seconds / 3600.0; lat = lat * (latString.endsWith("N") || latString.endsWith("E") ? 1.0 : -1.0); return lat; }  static Double parseDegrees(String latString); static boolean isValidLongitude(Double longitude); static boolean isValidLatitude(Double latitude); static LatLng parseLatLng(String latitude, String longitude);  }