GeoWidgetUtils { public static String convertCoordinatesIntoDegreeFormat(Context context, double coordinate, String type) { String coordinateDegrees = Location.convert(Math.abs(coordinate), Location.FORMAT_SECONDS); String[] coordinateSplit = coordinateDegrees.split(":"); String degrees = floor(coordinateSplit[0]) + "°"; String mins = floor(coordinateSplit[1]) + "'"; String secs = floor(coordinateSplit[2]) + '"'; return String.format(getCardinalDirection(context, coordinate, type), degrees, mins, secs); } private  GeoWidgetUtils(); static String convertCoordinatesIntoDegreeFormat(Context context, double coordinate, String type); static double[] getLocationParamsFromStringAnswer(String answer); static String truncateDouble(String s);  }
@Test public void convertCoordinatesIntoDegreeFormatTest() { Context context = RuntimeEnvironment.application; assertEquals("N 37°27'5\"", GeoWidgetUtils.convertCoordinatesIntoDegreeFormat(context, 37.45153333333334, "lat")); assertEquals("W 122°9'19\"", GeoWidgetUtils.convertCoordinatesIntoDegreeFormat(context, -122.15539166666667, "lon")); assertEquals("N 3°51'4\"", GeoWidgetUtils.convertCoordinatesIntoDegreeFormat(context, 3.8513583333333337, "lat")); assertEquals("W 70°2'11\"", GeoWidgetUtils.convertCoordinatesIntoDegreeFormat(context, -70.03650333333333, "lon")); assertEquals("S 31°8'40\"", GeoWidgetUtils.convertCoordinatesIntoDegreeFormat(context, -31.144546666666663, "lat")); assertEquals("E 138°16'15\"", GeoWidgetUtils.convertCoordinatesIntoDegreeFormat(context, 138.27083666666667, "lon")); assertEquals("N 61°23'15\"", GeoWidgetUtils.convertCoordinatesIntoDegreeFormat(context, 61.38757333333333, "lat")); assertEquals("W 150°55'37\"", GeoWidgetUtils.convertCoordinatesIntoDegreeFormat(context, -150.92708666666667, "lon")); assertEquals("N 0°0'0\"", GeoWidgetUtils.convertCoordinatesIntoDegreeFormat(context, 0, "lat")); assertEquals("E 0°0'0\"", GeoWidgetUtils.convertCoordinatesIntoDegreeFormat(context, 0, "lon")); }