Java tutorial
//package com.java2s; public class Main { /** * Returns the bearing from one point to another. * @param latFrom The latitude of the point from * @param lonFrom The longitude of the point from * @param latTo The latitude of the point to * @param lonTo The longitude of the point to * @return the bearing from one point to another */ private static double bearingTo(double latFrom, double lonFrom, double latTo, double lonTo) { double latitude1 = Math.toRadians(latFrom); double latitude2 = Math.toRadians(latTo); double longDiff = Math.toRadians(lonTo - lonFrom); double y = Math.sin(longDiff) * Math.cos(latitude2); double x = Math.cos(latitude1) * Math.sin(latitude2) - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(longDiff); return (Math.toDegrees(Math.atan2(y, x)) + 360) % 360; } }