@Test @Category(UnitTest.class) public void testBasics() throws Exception { LatLng p1, p2; p1 = new LatLng(0, 0); p2 = new LatLng(0, 1); Assert.assertEquals(111319.49079326246, LatLng.calculateGreatCircleDistance(p1, p2)); p1 = new LatLng(0, 0); p2 = new LatLng(1, 0); Assert.assertEquals(111319.49079326246, LatLng.calculateGreatCircleDistance(p1, p2)); }
public static double calculateGreatCircleDistance(LatLng p1, LatLng p2) { if (FloatUtils.isEqual(p1.getLat(), p2.getLat()) && FloatUtils.isEqual(p1.getLng(), p2.getLng())) { return 0.0; } double dsigma = Math.acos(Math.cos(p1.getLatAsRadians()) * Math.cos(p2.getLatAsRadians()) * Math.cos(p1.getLngAsRadians() - p2.getLngAsRadians()) + Math.sin(p1.getLatAsRadians()) * Math.sin(p2.getLatAsRadians())); return dsigma * EARTH_RADIUS; }
LatLng { public static double calculateGreatCircleDistance(LatLng p1, LatLng p2) { if (FloatUtils.isEqual(p1.getLat(), p2.getLat()) && FloatUtils.isEqual(p1.getLng(), p2.getLng())) { return 0.0; } double dsigma = Math.acos(Math.cos(p1.getLatAsRadians()) * Math.cos(p2.getLatAsRadians()) * Math.cos(p1.getLngAsRadians() - p2.getLngAsRadians()) + Math.sin(p1.getLatAsRadians()) * Math.sin(p2.getLatAsRadians())); return dsigma * EARTH_RADIUS; } }
LatLng { public static double calculateGreatCircleDistance(LatLng p1, LatLng p2) { if (FloatUtils.isEqual(p1.getLat(), p2.getLat()) && FloatUtils.isEqual(p1.getLng(), p2.getLng())) { return 0.0; } double dsigma = Math.acos(Math.cos(p1.getLatAsRadians()) * Math.cos(p2.getLatAsRadians()) * Math.cos(p1.getLngAsRadians() - p2.getLngAsRadians()) + Math.sin(p1.getLatAsRadians()) * Math.sin(p2.getLatAsRadians())); return dsigma * EARTH_RADIUS; } LatLng();  LatLng(double lat, double lng); }
LatLng { public static double calculateGreatCircleDistance(LatLng p1, LatLng p2) { if (FloatUtils.isEqual(p1.getLat(), p2.getLat()) && FloatUtils.isEqual(p1.getLng(), p2.getLng())) { return 0.0; } double dsigma = Math.acos(Math.cos(p1.getLatAsRadians()) * Math.cos(p2.getLatAsRadians()) * Math.cos(p1.getLngAsRadians() - p2.getLngAsRadians()) + Math.sin(p1.getLatAsRadians()) * Math.sin(p2.getLatAsRadians())); return dsigma * EARTH_RADIUS; } LatLng();  LatLng(double lat, double lng); static double calculateGreatCircleDistance(LatLng p1, LatLng p2); static LatLng calculateCartesianDestinationPoint(LatLng startPoint,
    double distanceInMeters,
    double bearing); double getLat(); void setLat(double lat); double getLng(); void setLng(double lng); @Override String toString(); void setX(double x); void setY(double y); }
LatLng { public static double calculateGreatCircleDistance(LatLng p1, LatLng p2) { if (FloatUtils.isEqual(p1.getLat(), p2.getLat()) && FloatUtils.isEqual(p1.getLng(), p2.getLng())) { return 0.0; } double dsigma = Math.acos(Math.cos(p1.getLatAsRadians()) * Math.cos(p2.getLatAsRadians()) * Math.cos(p1.getLngAsRadians() - p2.getLngAsRadians()) + Math.sin(p1.getLatAsRadians()) * Math.sin(p2.getLatAsRadians())); return dsigma * EARTH_RADIUS; } LatLng();  LatLng(double lat, double lng); static double calculateGreatCircleDistance(LatLng p1, LatLng p2); static LatLng calculateCartesianDestinationPoint(LatLng startPoint,
    double distanceInMeters,
    double bearing); double getLat(); void setLat(double lat); double getLng(); void setLng(double lng); @Override String toString(); void setX(double x); void setY(double y); final static double EARTH_RADIUS_MEAN; final static double EARTH_RADIUS_EQUATOR; final static double EARTH_RADIUS; final static double METERS_PER_DEGREE; }