Java tutorial
//package com.java2s; public class Main { public static double getBearing(double lat1, double lng1, double lat2, double lng2) { double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); lng1 = Math.toRadians(lng1); lng2 = Math.toRadians(lng2); double y = Math.sin(dLng) * Math.cos(lat2); double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLng); double brng = Math.toDegrees(Math.atan2(y, x)); return brng; } }