@Test public void testDistanceInMeters() { LatLon point1 = new LatLon(0,0); LatLon point2 = new LatLon(1,1); double d = LatLon.distanceInMeters(point1, point2); assertTrue((d > 111000) && (d < 1113000)); }
public static double distanceInMeters(final double lat1, final double lon1, final double lat2, final double lon2) { if(lat1==lat2 && lon1==lon2){ return 0; } final int constantTerm = 6378; final int factor1 = 21; double angle = Math.toRadians((lat1 + lat2) / 2); final int factor = (int) ((constantTerm - factor1 * Math.sin(angle)) * UnitConstants.KILO); final double p1lat = Math.toRadians(lat1); final double p2lat = Math.toRadians(lat2); return ( Math.acos( Math.sin(p1lat) * Math.sin(p2lat) + Math.cos(p1lat) * Math.cos(p2lat) * Math.cos(Math.toRadians(lon2 - lon1)) ) * factor); }
LatLon extends Coordinate implements Serializable, Externalizable { public static double distanceInMeters(final double lat1, final double lon1, final double lat2, final double lon2) { if(lat1==lat2 && lon1==lon2){ return 0; } final int constantTerm = 6378; final int factor1 = 21; double angle = Math.toRadians((lat1 + lat2) / 2); final int factor = (int) ((constantTerm - factor1 * Math.sin(angle)) * UnitConstants.KILO); final double p1lat = Math.toRadians(lat1); final double p2lat = Math.toRadians(lat2); return ( Math.acos( Math.sin(p1lat) * Math.sin(p2lat) + Math.cos(p1lat) * Math.cos(p2lat) * Math.cos(Math.toRadians(lon2 - lon1)) ) * factor); } }
LatLon extends Coordinate implements Serializable, Externalizable { public static double distanceInMeters(final double lat1, final double lon1, final double lat2, final double lon2) { if(lat1==lat2 && lon1==lon2){ return 0; } final int constantTerm = 6378; final int factor1 = 21; double angle = Math.toRadians((lat1 + lat2) / 2); final int factor = (int) ((constantTerm - factor1 * Math.sin(angle)) * UnitConstants.KILO); final double p1lat = Math.toRadians(lat1); final double p2lat = Math.toRadians(lat2); return ( Math.acos( Math.sin(p1lat) * Math.sin(p2lat) + Math.cos(p1lat) * Math.cos(p2lat) * Math.cos(Math.toRadians(lon2 - lon1)) ) * factor); } @Deprecated  LatLon();  LatLon(final double lat, final double lon); }
LatLon extends Coordinate implements Serializable, Externalizable { public static double distanceInMeters(final double lat1, final double lon1, final double lat2, final double lon2) { if(lat1==lat2 && lon1==lon2){ return 0; } final int constantTerm = 6378; final int factor1 = 21; double angle = Math.toRadians((lat1 + lat2) / 2); final int factor = (int) ((constantTerm - factor1 * Math.sin(angle)) * UnitConstants.KILO); final double p1lat = Math.toRadians(lat1); final double p2lat = Math.toRadians(lat2); return ( Math.acos( Math.sin(p1lat) * Math.sin(p2lat) + Math.cos(p1lat) * Math.cos(p2lat) * Math.cos(Math.toRadians(lon2 - lon1)) ) * factor); } @Deprecated  LatLon();  LatLon(final double lat, final double lon); double lat(); double lon(); boolean equalsEpsilon(final LatLon other); boolean isOutSideWorld(); boolean isWithin(final Bounds b); @Override String toString(); static double distanceToKilomters(final double aDist); static double dist(final double lat1, final double lon1,
            final double lat2, final double lon2); static double course(final double lat1, final double lon1,
            final double lat2, final double lon2); static double xtd(final double lat1, final double lon1,
            final double lat2, final double lon2,
            final double lat3, final double lon3); static double distanceInMeters(final double lat1, final double lon1, final double lat2, final double lon2); static double distanceInMeters(final LatLon point1, final LatLon point2); static double distanceInMeters(final Node point1, final Node point2); static double deriveCourse(final double lat1, final double lon1, final double lat2, final double lon2); @Override void readExternal(final ObjectInput aIn); @Override void writeExternal(final ObjectOutput aOut); }
LatLon extends Coordinate implements Serializable, Externalizable { public static double distanceInMeters(final double lat1, final double lon1, final double lat2, final double lon2) { if(lat1==lat2 && lon1==lon2){ return 0; } final int constantTerm = 6378; final int factor1 = 21; double angle = Math.toRadians((lat1 + lat2) / 2); final int factor = (int) ((constantTerm - factor1 * Math.sin(angle)) * UnitConstants.KILO); final double p1lat = Math.toRadians(lat1); final double p2lat = Math.toRadians(lat2); return ( Math.acos( Math.sin(p1lat) * Math.sin(p2lat) + Math.cos(p1lat) * Math.cos(p2lat) * Math.cos(Math.toRadians(lon2 - lon1)) ) * factor); } @Deprecated  LatLon();  LatLon(final double lat, final double lon); double lat(); double lon(); boolean equalsEpsilon(final LatLon other); boolean isOutSideWorld(); boolean isWithin(final Bounds b); @Override String toString(); static double distanceToKilomters(final double aDist); static double dist(final double lat1, final double lon1,
            final double lat2, final double lon2); static double course(final double lat1, final double lon1,
            final double lat2, final double lon2); static double xtd(final double lat1, final double lon1,
            final double lat2, final double lon2,
            final double lat3, final double lon3); static double distanceInMeters(final double lat1, final double lon1, final double lat2, final double lon2); static double distanceInMeters(final LatLon point1, final LatLon point2); static double distanceInMeters(final Node point1, final Node point2); static double deriveCourse(final double lat1, final double lon1, final double lat2, final double lon2); @Override void readExternal(final ObjectInput aIn); @Override void writeExternal(final ObjectOutput aOut);  }