uk.me.jstott.jcoord
Class LatLng

java.lang.Object
  extended by uk.me.jstott.jcoord.LatLng

public class LatLng
extends java.lang.Object

This class is part of the Jcoord package. Visit the Jcoord website for more information.

Class to represent a latitude/longitude pair based on a particular datum.

(c) 2006 Jonathan Stott

Created on 11-02-2006

Since:
1.0
Version:
1.1
Author:
Jonathan Stott

Field Summary
static int EAST
          Longitude is east of the prime meridian.
static int NORTH
          Latitude is north of the equator.
static int SOUTH
          Latitude is south of the equator.
static int WEST
          Longitude is west of the prime meridian.
 
Constructor Summary
LatLng(double latitude, double longitude)
          Create a new LatLng object to represent a latitude/longitude pair using the WGS84 datum.
LatLng(double latitude, double longitude, double height)
          Create a new LatLng object to represent a latitude/longitude pair using the WGS84 datum.
LatLng(double latitude, double longitude, double height, Datum datum)
          Create a new LatLng object to represent a latitude/longitude pair using the specified datum.
LatLng(int latitudeDegrees, int latitudeMinutes, double latitudeSeconds, int northSouth, int longitudeDegrees, int longitudeMinutes, double longitudeSeconds, int eastWest)
          Create a new LatLng object to represent a latitude/longitude pair using the WGS84 datum.
LatLng(int latitudeDegrees, int latitudeMinutes, double latitudeSeconds, int northSouth, int longitudeDegrees, int longitudeMinutes, double longitudeSeconds, int eastWest, double height)
          Create a new LatLng object to represent a latitude/longitude pair using the WGS84 datum.
LatLng(int latitudeDegrees, int latitudeMinutes, double latitudeSeconds, int northSouth, int longitudeDegrees, int longitudeMinutes, double longitudeSeconds, int eastWest, double height, Datum datum)
          Create a new LatLng object to represent a latitude/longitude pair using the specified datum.
 
Method Summary
 double distance(LatLng ll)
          Calculate the surface distance in kilometres from this LatLng to the given LatLng.
 double distanceMiles(LatLng ll)
          Calculate the surface distance in miles from this LatLng to the given LatLng.
 Datum getDatum()
          Get the datum.
 double getHeight()
          Get the height.
 double getLat()
          Deprecated. Use getLatitude() instead.
 double getLatitude()
          Return the latitude in degrees.
 int getLatitudeDegrees()
           
 int getLatitudeMinutes()
           
 double getLatitudeSeconds()
           
 double getLng()
          Deprecated. Use getLongitude() instead.
 double getLongitude()
          Return the longitude in degrees.
 int getLongitudeDegrees()
           
 int getLongitudeMinutes()
           
 double getLongitudeSeconds()
           
 void toDatum(Datum d)
           
 java.lang.String toDMSString()
          Return a String representation of this LatLng object in degrees-minutes-seconds format.
 MGRSRef toMGRSRef()
          Convert this latitude and longitude to an MGRS reference.
 void toOSGB36()
          Convert this LatLng from the WGS84 datum to the OSGB36 datum using an approximate Helmert transformation.
 OSRef toOSRef()
          Convert this latitude and longitude into an OSGB (Ordnance Survey of Great Britain) grid reference.
 java.lang.String toString()
          Get a String representation of this LatLng object.
 UTMRef toUTMRef()
          Convert this latitude and longitude to a UTM reference.
 void toWGS84()
          Convert this LatLng from the OSGB36 datum to the WGS84 datum using an approximate Helmert transformation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NORTH

public static final int NORTH
Latitude is north of the equator.

See Also:
Constant Field Values

SOUTH

public static final int SOUTH
Latitude is south of the equator.

See Also:
Constant Field Values

EAST

public static final int EAST
Longitude is east of the prime meridian.

See Also:
Constant Field Values

WEST

public static final int WEST
Longitude is west of the prime meridian.

See Also:
Constant Field Values
Constructor Detail

LatLng

public LatLng(double latitude,
              double longitude)
Create a new LatLng object to represent a latitude/longitude pair using the WGS84 datum.

Parameters:
latitude - the latitude in degrees. Must be between -90.0 and 90.0 inclusive. -90.0 and 90.0 are effectively equivalent.
longitude - the longitude in degrees. Must be between -180.0 and 180.0 inclusive. -180.0 and 180.0 are effectively equivalent.
Throws:
java.lang.IllegalArgumentException - if either the given latitude or the given longitude are invalid.
Since:
1.0

LatLng

public LatLng(double latitude,
              double longitude,
              double height)
Create a new LatLng object to represent a latitude/longitude pair using the WGS84 datum.

Parameters:
latitude - the latitude in degrees. Must be between -90.0 and 90.0 inclusive. -90.0 and 90.0 are effectively equivalent.
longitude - the longitude in degrees. Must be between -180.0 and 180.0 inclusive. -180.0 and 180.0 are effectively equivalent.
height - the perpendicular height above the reference ellipsoid.
Throws:
java.lang.IllegalArgumentException - if either the given latitude or the given longitude are invalid.
Since:
1.1

LatLng

public LatLng(int latitudeDegrees,
              int latitudeMinutes,
              double latitudeSeconds,
              int northSouth,
              int longitudeDegrees,
              int longitudeMinutes,
              double longitudeSeconds,
              int eastWest)
       throws java.lang.IllegalArgumentException
Create a new LatLng object to represent a latitude/longitude pair using the WGS84 datum.

Parameters:
latitudeDegrees - the degrees part of the latitude. Must be 0 <= latitudeDegrees <= 90.0.
latitudeMinutes - the minutes part of the latitude. Must be 0 <= latitudeMinutes < 60.0.
latitudeSeconds - the seconds part of the latitude. Must be 0 <= latitudeSeconds < 60.0.
northSouth - whether the latitude is north or south of the equator. One of LatLng.NORTH or LatLng.SOUTH.
longitudeDegrees - the degrees part of the longitude. Must be 0 <= longitudeDegrees <= 90.0.
longitudeMinutes - the minutes part of the longitude. Must be 0 <= longitudeMinutes < 60.0.
longitudeSeconds - the seconds part of the longitude. Must be 0 <= longitudeSeconds < 60.0.
eastWest - whether the longitude is east or west of the prime meridian. One of LatLng.EAST or LatLng.WEST.
Throws:
java.lang.IllegalArgumentException - if any of the parameters are invalid.
Since:
1.1

LatLng

public LatLng(int latitudeDegrees,
              int latitudeMinutes,
              double latitudeSeconds,
              int northSouth,
              int longitudeDegrees,
              int longitudeMinutes,
              double longitudeSeconds,
              int eastWest,
              double height)
       throws java.lang.IllegalArgumentException
Create a new LatLng object to represent a latitude/longitude pair using the WGS84 datum.

Parameters:
latitudeDegrees - the degrees part of the latitude. Must be 0 <= latitudeDegrees <= 90.0.
latitudeMinutes - the minutes part of the latitude. Must be 0 <= latitudeMinutes < 60.0.
latitudeSeconds - the seconds part of the latitude. Must be 0 <= latitudeSeconds < 60.0.
northSouth - whether the latitude is north or south of the equator. One of LatLng.NORTH or LatLng.SOUTH.
longitudeDegrees - the degrees part of the longitude. Must be 0 <= longitudeDegrees <= 90.0.
longitudeMinutes - the minutes part of the longitude. Must be 0 <= longitudeMinutes < 60.0.
longitudeSeconds - the seconds part of the longitude. Must be 0 <= longitudeSeconds < 60.0.
eastWest - whether the longitude is east or west of the prime meridian. One of LatLng.EAST or LatLng.WEST.
height - the perpendicular height above the reference ellipsoid.
Throws:
java.lang.IllegalArgumentException - if any of the parameters are invalid.
Since:
1.1

LatLng

public LatLng(int latitudeDegrees,
              int latitudeMinutes,
              double latitudeSeconds,
              int northSouth,
              int longitudeDegrees,
              int longitudeMinutes,
              double longitudeSeconds,
              int eastWest,
              double height,
              Datum datum)
       throws java.lang.IllegalArgumentException
Create a new LatLng object to represent a latitude/longitude pair using the specified datum.

Parameters:
latitudeDegrees - the degrees part of the latitude. Must be 0 <= latitudeDegrees <= 90.0.
latitudeMinutes - the minutes part of the latitude. Must be 0 <= latitudeMinutes < 60.0.
latitudeSeconds - the seconds part of the latitude. Must be 0 <= latitudeSeconds < 60.0.
northSouth - whether the latitude is north or south of the equator. One of LatLng.NORTH or LatLng.SOUTH.
longitudeDegrees - the degrees part of the longitude. Must be 0 <= longitudeDegrees <= 90.0.
longitudeMinutes - the minutes part of the longitude. Must be 0 <= longitudeMinutes < 60.0.
longitudeSeconds - the seconds part of the longitude. Must be 0 <= longitudeSeconds < 60.0.
eastWest - whether the longitude is east or west of the prime meridian. One of LatLng.EAST or LatLng.WEST.
height - the perpendicular height above the reference ellipsoid.
datum - the datum that this reference is based on.
Throws:
java.lang.IllegalArgumentException - if any of the parameters are invalid.
Since:
1.1

LatLng

public LatLng(double latitude,
              double longitude,
              double height,
              Datum datum)
       throws java.lang.IllegalArgumentException
Create a new LatLng object to represent a latitude/longitude pair using the specified datum.

Parameters:
latitude - the latitude in degrees. Must be between -90.0 and 90.0 inclusive. -90.0 and 90.0 are effectively equivalent.
longitude - the longitude in degrees. Must be between -180.0 and 180.0 inclusive. -180.0 and 180.0 are effectively equivalent.
height - the perpendicular height above the reference ellipsoid.
datum - the datum that this reference is based on.
Throws:
java.lang.IllegalArgumentException - if either the given latitude or the given longitude are invalid.
Since:
1.1
Method Detail

toString

public java.lang.String toString()
Get a String representation of this LatLng object.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of this LatLng object.
Since:
1.0

toDMSString

public java.lang.String toDMSString()
Return a String representation of this LatLng object in degrees-minutes-seconds format. The returned format will be like this: DD MM SS.SSS N DD MM SS.SSS E where DD is the number of degrees, MM is the number of minutes, SS.SSS is the number of seconds, N is either N or S to indicate north or south of the equator and E is either E or W to indicate east or west of the prime meridian.

Returns:
a String representation of this LatLng object in DMS format.
Since:
1.1

toOSRef

public OSRef toOSRef()
Convert this latitude and longitude into an OSGB (Ordnance Survey of Great Britain) grid reference.

Returns:
the converted OSGB grid reference.
Since:
1.0

toUTMRef

public UTMRef toUTMRef()
                throws NotDefinedOnUTMGridException
Convert this latitude and longitude to a UTM reference.

Returns:
the converted UTM reference.
Throws:
NotDefinedOnUTMGridException - if an attempt is made to convert a LatLng that falls outside the area covered by the UTM grid. The UTM grid is only defined for latitudes south of 84°N and north of 80°S.
Since:
1.0

toMGRSRef

public MGRSRef toMGRSRef()
Convert this latitude and longitude to an MGRS reference.

Returns:
the converted MGRS reference
Since:
1.1

toWGS84

public void toWGS84()
Convert this LatLng from the OSGB36 datum to the WGS84 datum using an approximate Helmert transformation.

Since:
1.0

toDatum

public void toDatum(Datum d)
Parameters:
d -
Since:
1.1

toOSGB36

public void toOSGB36()
Convert this LatLng from the WGS84 datum to the OSGB36 datum using an approximate Helmert transformation.

Since:
1.0

distance

public double distance(LatLng ll)
Calculate the surface distance in kilometres from this LatLng to the given LatLng.

Parameters:
ll - the LatLng object to measure the distance to.
Returns:
the surface distance in kilometres.
Since:
1.0

distanceMiles

public double distanceMiles(LatLng ll)
Calculate the surface distance in miles from this LatLng to the given LatLng.

Parameters:
ll - the LatLng object to measure the distance to.
Returns:
the surface distance in miles.
Since:
1.1

getLat

public double getLat()
Deprecated. Use getLatitude() instead.

Return the latitude in degrees.

Returns:
the latitude in degrees.
Since:
1.0

getLatitude

public double getLatitude()
Return the latitude in degrees.

Returns:
the latitude in degrees.
Since:
1.1

getLatitudeDegrees

public int getLatitudeDegrees()
Returns:
Since:
1.1

getLatitudeMinutes

public int getLatitudeMinutes()
Returns:
Since:
1.1

getLatitudeSeconds

public double getLatitudeSeconds()
Returns:
Since:
1.1

getLng

public double getLng()
Deprecated. Use getLongitude() instead.

Return the longitude in degrees.

Returns:
the longitude in degrees.
Since:
1.0

getLongitude

public double getLongitude()
Return the longitude in degrees.

Returns:
the longitude in degrees.
Since:
1.0

getLongitudeDegrees

public int getLongitudeDegrees()
Returns:
Since:
1.1

getLongitudeMinutes

public int getLongitudeMinutes()
Returns:
Since:
1.1

getLongitudeSeconds

public double getLongitudeSeconds()
Returns:
Since:
1.1

getHeight

public double getHeight()
Get the height.

Returns:
the height.
Since:
1.1

getDatum

public Datum getDatum()
Get the datum.

Returns:
the datum.
Since:
1.1