DistanceCalculator { public static double distanceBetweenPoints(final Position start, final Position end, final MeasuringUnit unit) { final double distance = distance(start.getLatitude(), start.getLongitude(), end.getLatitude(), end.getLongitude(), unit); return distance; }  static double distance(final double startLatitude, final double startLongitude,
		final double endLatitude, final double endLongitude, final MeasuringUnit unit); static double distanceBetweenPoints(final Position start, final Position end,
		final MeasuringUnit unit); static double distanceBetweenPoints(final String startGeohashValue,
		final String endGeohashValue, final MeasuringUnit unit);  }
@Test(enabled = true) public void testDistanceBetweenPointsPositionPositionMeasuringUnit() { double actual; double expected; final String alterTeichwegGeohash = "u1x0v54rmjwej"; final double[] coordinates = GeoHashExtensions.decodeAndRound(alterTeichwegGeohash); final Position alterTeichweg = new Point(coordinates[0], coordinates[1]); final Position ludwigsburg = new GeoHashPoint(48.889380, 9.190459); actual = DistanceCalculator.distanceBetweenPoints(ludwigsburg, alterTeichweg, MeasuringUnit.KILOMETER); expected = 525.875517661088d; assertEquals(expected, actual); }
@Test(enabled = true) public void testDistanceBetweenPointsStringStringMeasuringUnit() { double actual; double expected; final String alterTeichwegGeohash = "u1x0v54rmjwej"; final String subGeohash = alterTeichwegGeohash.substring(0, 1); final Map<String, String> firstRingCells = GeoHashExtensions .getAllAdjacentAreasMap(subGeohash); final Position ludwigsburg = new GeoHashPoint(48.889380, 9.190459); final String ludwigsburgGeohash = ((GeoHashPoint)ludwigsburg).getGeohash(); actual = DistanceCalculator.distanceBetweenPoints(ludwigsburgGeohash, alterTeichwegGeohash, MeasuringUnit.KILOMETER); expected = 525.875517737948d; assertEquals(expected, actual); actual = DistanceCalculator.distanceBetweenPoints(ludwigsburgGeohash, alterTeichwegGeohash, MeasuringUnit.METER); expected = 525875.517737948d; assertEquals(expected, actual); actual = DistanceCalculator.distanceBetweenPoints(firstRingCells.get(Adjacent.CENTER), firstRingCells.get(Adjacent.RIGHT), MeasuringUnit.KILOMETER); expected = 1872.667779425215d; assertEquals(expected, actual); actual = DistanceCalculator.distanceBetweenPoints(firstRingCells.get(Adjacent.CENTER), firstRingCells.get(Adjacent.BOTTOM), MeasuringUnit.KILOMETER); expected = 5003.530963199998d; assertEquals(expected, actual); actual = DistanceCalculator.distanceBetweenPoints(firstRingCells.get(Adjacent.CENTER), firstRingCells.get(Adjacent.RIGHT), MeasuringUnit.MILE); expected = 1010.4891804690958d; assertEquals(expected, actual); actual = DistanceCalculator.distanceBetweenPoints(firstRingCells.get(Adjacent.CENTER), firstRingCells.get(Adjacent.BOTTOM), MeasuringUnit.MILE); expected = 2699.899019999999d; assertEquals(expected, actual); }