com.TwentyCodes.android.location
Class GeoUtils

java.lang.Object
  extended by com.TwentyCodes.android.location.GeoUtils

public class GeoUtils
extends Object

This class contains common tools for computing common geological problems

Author:
ricky barrette, Google Inc.

Field Summary
static int EARTH_RADIUS_KM
           
static double MILLION
           
 
Constructor Summary
GeoUtils()
           
 
Method Summary
static double bearing(double lat1, double lon1, double lat2, double lon2)
          computes the bearing of lat2/lon2 in relationship from lat1/lon1 in degrees East
static double bearing(GeoPoint p1, GeoPoint p2)
          computes the bearing of lat2/lon2 in relationship from lat1/lon1 in degrees East
static GeoPoint distanceFrom(GeoPoint point, double distance)
          Calculates a geopoint x meters away of the geopoint supplied.
static double distanceKm(double lat1, double lon1, double lat2, double lon2)
          computes the distance between to lat1/lon1 and lat2/lon2 based on the curve of the earth
static double distanceKm(GeoPoint p1, GeoPoint p2)
          computes the distance between to p1 and p2 based on the curve of the earth
static boolean isIntersecting(GeoPoint userPoint, float accuracyRadius, GeoPoint locationPoint, float locationRadius, float fudgeFactor)
          a convince method for testing if 2 circles on the the surface of the earth intersect.
static MidPoint midPoint(GeoPoint p1, GeoPoint p2)
          computes a geopoint the is the central geopoint between p1 and p1
static double radToBearing(double rad)
          converts radians to bearing
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EARTH_RADIUS_KM

public static final int EARTH_RADIUS_KM
See Also:
Constant Field Values

MILLION

public static final double MILLION
See Also:
Constant Field Values
Constructor Detail

GeoUtils

public GeoUtils()
Method Detail

bearing

public static double bearing(double lat1,
                             double lon1,
                             double lat2,
                             double lon2)
computes the bearing of lat2/lon2 in relationship from lat1/lon1 in degrees East

Parameters:
lat1 - source lat
lon1 - source lon
lat2 - destination lat
lon2 - destination lon
Returns:
the bearing of lat2/lon2 in relationship from lat1/lon1 in degrees East

bearing

public static double bearing(GeoPoint p1,
                             GeoPoint p2)
computes the bearing of lat2/lon2 in relationship from lat1/lon1 in degrees East

Parameters:
p1 - source geopoint
p2 - destination geopoint
Returns:
the bearing of p2 in relationship from p1 in degrees East

distanceFrom

public static GeoPoint distanceFrom(GeoPoint point,
                                    double distance)
Calculates a geopoint x meters away of the geopoint supplied. The new geopoint shares the same latitude as geopoint point, this way they are on the same latitude arc.

Parameters:
point - central geopoint
distance - in meters from the geopoint
Returns:
geopoint that is x meters away from the geopoint supplied

distanceKm

public static double distanceKm(double lat1,
                                double lon1,
                                double lat2,
                                double lon2)
computes the distance between to lat1/lon1 and lat2/lon2 based on the curve of the earth

Parameters:
lat1 - source lat
lon1 - source lon
lat2 - destination lat
lon2 - destination lon
Returns:
the distance between to lat1/lon1 and lat2/lon2

isIntersecting

public static boolean isIntersecting(GeoPoint userPoint,
                                     float accuracyRadius,
                                     GeoPoint locationPoint,
                                     float locationRadius,
                                     float fudgeFactor)
a convince method for testing if 2 circles on the the surface of the earth intersect. we will use this method to test if the users accuracy circle intersects a marked locaton's radius if ( (accuracyCircleRadius + locationRadius) - fudgeFactor) > acos(sin(lat1Rad)sin(lat2Rad)+cos(lat1Rad)cos(lat2Rad)cos(lon2Rad-lon1Rad)6371

Parameters:
userPoint -
accuracyRadius - in KM
locationPoint -
locationRadius - in KM
fudgeFactor - how many KM the circles have to intersect
Returns:
true if the circles intersect

distanceKm

public static double distanceKm(GeoPoint p1,
                                GeoPoint p2)
computes the distance between to p1 and p2 based on the curve of the earth

Parameters:
p1 -
p2 -
Returns:
the distance between to p1 and p2

midPoint

public static MidPoint midPoint(GeoPoint p1,
                                GeoPoint p2)
computes a geopoint the is the central geopoint between p1 and p1

Parameters:
p1 - first geopoint
p2 - second geopoint
Returns:
a MidPoint object

radToBearing

public static double radToBearing(double rad)
converts radians to bearing

Parameters:
rad -
Returns:
bearing