com.ulocate.api.geo
Class GeoCalc

java.lang.Object
  extended by com.ulocate.api.geo.GeoCalc

public class GeoCalc
extends java.lang.Object

GeoCalc provides functions for distance calculations between two points on the earth's surface.
The functions give results that should be accurate enough for any LBS application.
The most accurate function provided here is based on a sphere.

Version:
0.2
Author:
uLocate Communications, © 2007

Field Summary
static double EARTH_RADIUS
          Average earth radius in miles.
static double FEET
          Unit of measurement value for feet.
static double KILOMETERS
          Unit of measurement value for kilometers.
static double METERS
          Unit of measurement value for meters.
static double MILES
          Unit of measurement value for miles.
static double MILES_PER_DEGREE_LATITUDE
          Miles per degree of Latitude.
static double YARDS
          Unit of measurement value for yards.
 
Constructor Summary
GeoCalc()
           
 
Method Summary
 double getDistanceAccurate(double lon1, double lat1, double lon2, double lat2, double uom)
          Calculates the distance between two points (given by Latitude and Longitude).
 double getDistanceApproximate(double lon1, double lat1, double lon2, double lat2, double uom)
          Calculates an estimated distance between two points (given by Latitude and Longitude).
 double getDistanceRough(double lon1, double lat1, double lon2, double lat2, double uom)
          Calculates an estimated distance between two points (given by Latitude and Longitude).
 double getMilesPerDegreeLongitude(double latitude)
          Calculates the number of miles per degree of Longitude at a given Latitude.
 double[] getSearchMBR(double distance, double uom, double longitude, double latitude)
          Calculates the minimum bounding rectangle of the search area.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EARTH_RADIUS

public static final double EARTH_RADIUS
Average earth radius in miles.

See Also:
Constant Field Values

FEET

public static final double FEET
Unit of measurement value for feet.

See Also:
Constant Field Values

KILOMETERS

public static final double KILOMETERS
Unit of measurement value for kilometers.

See Also:
Constant Field Values

METERS

public static final double METERS
Unit of measurement value for meters.

See Also:
Constant Field Values

MILES

public static final double MILES
Unit of measurement value for miles.

See Also:
Constant Field Values

MILES_PER_DEGREE_LATITUDE

public static final double MILES_PER_DEGREE_LATITUDE
Miles per degree of Latitude.

See Also:
Constant Field Values

YARDS

public static final double YARDS
Unit of measurement value for yards.

See Also:
Constant Field Values
Constructor Detail

GeoCalc

public GeoCalc()
Method Detail

getDistanceAccurate

public double getDistanceAccurate(double lon1,
                                  double lat1,
                                  double lon2,
                                  double lat2,
                                  double uom)
Calculates the distance between two points (given by Latitude and Longitude).
This calculation uses the 'Great Circle Distance Formula' and is more accurate
but slower than the other two calculations.

Parameters:
lon1 - Longitude of point 1.
lat1 - Latitude of point 1.
lon2 - Longitude of point 2.
lat2 - Latitude of point 2.
uom - Unit of measurement.
Returns:
Returns the distance in the specified unit of measurement.

getDistanceApproximate

public double getDistanceApproximate(double lon1,
                                     double lat1,
                                     double lon2,
                                     double lat2,
                                     double uom)
Calculates an estimated distance between two points (given by Latitude and Longitude).
This calculation is an estimate. It performs slightly slower than the rough calculation
but much faster than the accurate calculation.

Parameters:
lon1 - Longitude of point 1.
lat1 - Latitude of point 1.
lon2 - Longitude of point 2.
lat2 - Latitude of point 2.
uom - Unit of measurement.
Returns:
Returns the distance in the specified unit of measurement.

getDistanceRough

public double getDistanceRough(double lon1,
                               double lat1,
                               double lon2,
                               double lat2,
                               double uom)
Calculates an estimated distance between two points (given by Latitude and Longitude).
This calculation is a rough estimate. It performs slightly faster than the other
approximate calculation but much faster than the accurate calculation.

Parameters:
lon1 - Longitude of point 1.
lat1 - Latitude of point 1.
lon2 - Longitude of point 2.
lat2 - Latitude of point 2.
uom - Unit of measurement.
Returns:
Returns the distance in the specified unit of measurement.

getMilesPerDegreeLongitude

public double getMilesPerDegreeLongitude(double latitude)
Calculates the number of miles per degree of Longitude at a given Latitude.

Parameters:
latitude -
Returns:
Number of miles per degree Longitude.

getSearchMBR

public double[] getSearchMBR(double distance,
                             double uom,
                             double longitude,
                             double latitude)
Calculates the minimum bounding rectangle of the search area.
The bounding rectangle is given by the minimum and maximum Latitude and Longitude.

Parameters:
distance - Search distance.
uom - Unit of measurement for search distance.
longitude - Longitude of the search center.
latitude - Latitude of the search center.
Returns:
Array of double: minLat, minLng, maxLat, maxLng.