/** * This is some of Nicky's wizardry. * It calculates the heading from 1 lat/lon to another lat/lon */ public static int getHeading( double oldlat, double oldlon, double newlat, double newlon ) { System.out.println("Called with " + Double.toString(newlat) + "," + Double.toString(newlon) + " : " + Double.toString(oldlat) + "," + Double.toString(oldlon) ); if (newlon == oldlon){ if (newlat < oldlat) return 180; else return 0; } if (newlat == oldlat){ if (newlon > oldlon) return 90; else if (newlon < oldlon) return 270; } if ((newlat > oldlat) && (newlon > oldlon)) { double difflat = java.lang.Math.abs(newlat - oldlat); double difflon = java.lang.Math.abs( newlon - oldlon ); double ratio = difflon / difflat; double tmp = mMath.atan( ratio ); return (int) java.lang.Math.toDegrees(tmp); } else if ((newlon > oldlon) && (newlat < oldlat)) return 180 - (int) java.lang.Math.toDegrees(mMath.atan( java.lang.Math.abs( newlon - oldlon ) / java.lang.Math.abs(newlat - oldlat) )); else if ((newlat < oldlat) && (newlon < oldlon)) { double difflat = java.lang.Math.abs(newlat - oldlat); double difflon = java.lang.Math.abs( newlon - oldlon ); double ratio = difflon/ difflat; double tmp = mMath.atan( ratio ); return 180 + (int) java.lang.Math.toDegrees(tmp); } else { double difflat = java.lang.Math.abs(newlat - oldlat); double difflon = java.lang.Math.abs( newlon - oldlon ); double ratio = difflon / difflat; double tmp = mMath.atan( ratio ); return 360 - (int) java.lang.Math.toDegrees(tmp); } }