Java tutorial
//package com.java2s; public class Main { /** * Calculate the azimuth to the target location from local. */ private static int getPosDirection(final double startlat, final double startlong, final double endlat, final double endlon) { double slat = Math.toRadians(startlat); double elat = Math.toRadians(endlat); double slng = Math.toRadians(startlong); double elng = Math.toRadians(endlon); double Y = Math.sin(elng - slng) * Math.cos(elat); double X = Math.cos(slat) * Math.sin(elat) - Math.sin(slat) * Math.cos(elat) * Math.cos(elng - slng); double deg = Math.toDegrees(Math.atan2(Y, X)); double angle = (deg + 360) % 360; return (int) (Math.abs(angle) + (1 / 7200)); } }