com.javadocmd.simplelatlng
Class LatLngTool

java.lang.Object
  extended by com.javadocmd.simplelatlng.LatLngTool

public class LatLngTool
extends Object

Primary calculations and tools.

Note: distance calculations are done using the Haversine formula which uses a spherical approximation of the Earth. Values are known to differ from reality by as much as 0.3% so if complete accuracy is very important to you, you should be using a different library. Furthermore, by default this library uses the mean radius of the Earth (6371.009 km). If your calculations are localized to a particular region of the Earth, there may be values to use for this radius which will yield more accurate results. To set the radius used by this library, see LatLngConfig.

Author:
Tyler Coles

Method Summary
static double distance(LatLng point1, LatLng point2, LengthUnit unit)
          Distance between two points.
static double distanceInRadians(LatLng point1, LatLng point2)
          This "distance" function is mostly for internal use.
static double initialBearing(LatLng start, LatLng end)
          Calculate the initial bearing in degrees on a great-circle course from one point to another.
static double initialBearingInRadians(LatLng start, LatLng end)
          Calculate the initial bearing in radians on a great-circle course from one point to another.
static double normalizeBearing(double bearing)
          Convert a bearing to be within the 0 to +360 degrees range.
static double normalizeLatitude(double latitude)
          Clamp latitude to +/- 90 degrees.
static double normalizeLongitude(double longitude)
          Convert longitude to be within the +/- 180 degrees range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

distance

public static double distance(LatLng point1,
                              LatLng point2,
                              LengthUnit unit)
Distance between two points.

Parameters:
point1 - the first point.
point2 - the second point.
unit - the unit of measure in which to receive the result.
Returns:
the distance in the chosen unit of measure.

distanceInRadians

public static double distanceInRadians(LatLng point1,
                                       LatLng point2)

This "distance" function is mostly for internal use. Most users will simply rely upon distance(LatLng, LatLng, LengthUnit)

Yields the internal angle for an arc between two points on the surface of a sphere in radians. This angle is in the plane of the great circle connecting the two points measured from an axis through one of the points and the center of the Earth. Multiply this value by the sphere's radius to get the length of the arc.

Returns:
the internal angle for the arc connecting the two points in radians.

initialBearing

public static double initialBearing(LatLng start,
                                    LatLng end)

Calculate the initial bearing in degrees on a great-circle course from one point to another.

Remember, you can calculate the final bearing by swapping the start/end points and reversing the resulting "initial" bearing by adding or subtracting 180 degrees.

Parameters:
start - the starting point.
end - the ending point.
Returns:
the initial bearing in degrees, normalized to the 0 to +360 range.

initialBearingInRadians

public static double initialBearingInRadians(LatLng start,
                                             LatLng end)

Calculate the initial bearing in radians on a great-circle course from one point to another.

Remember, you can calculate the final bearing by swapping the start/end points and reversing the resulting "initial" bearing by adding or subtracting 180 degrees.

Parameters:
start - the starting point.
end - the ending point.
Returns:
the initial bearing in radians.

normalizeLatitude

public static double normalizeLatitude(double latitude)
Clamp latitude to +/- 90 degrees.

Parameters:
latitude - in degrees.
Returns:
the normalized latitude. Returns NaN if the input is NaN.

normalizeLongitude

public static double normalizeLongitude(double longitude)
Convert longitude to be within the +/- 180 degrees range.

Parameters:
longitude - in degrees.
Returns:
the normalized longitude. Returns NaN if the input is NaN, positive infinity, or negative infinity.

normalizeBearing

public static double normalizeBearing(double bearing)
Convert a bearing to be within the 0 to +360 degrees range.

Parameters:
bearing - the bearing in degrees.
Returns:
the normalized breaing. Returns NaN if the input is NaN, positive infinity, or negative infinity.


Copyright © 2010-2013. All Rights Reserved.