Skip to content

Instantly share code, notes, and snippets.

@hogart
Last active January 23, 2018 00:50
Show Gist options
  • Save hogart/feac665ad24a72f8218be19a3a49d338 to your computer and use it in GitHub Desktop.
Save hogart/feac665ad24a72f8218be19a3a49d338 to your computer and use it in GitHub Desktop.
const EARTH_RADIUS = 6378137;
function toDeg(angle) {
return angle * 180 / Math.PI;
}
function toRad(angle) {
return angle * Math.PI / 180;
}
function solveDirectProblem3(lat, lng, azimuth, distance) {
var δ = distance / EARTH_RADIUS;
var θ = toRad(azimuth);
var φ1 = toRad(lat);
var λ1 = toRad(lng);
var sinφ1 = Math.sin(φ1),
cosφ1 = Math.cos(φ1);
var sinδ = Math.sin(δ),
cosδ = Math.cos(δ);
var sinθ = Math.sin(θ),
cosθ = Math.cos(θ);
var sinφ2 = sinφ1*cosδ + cosφ1*sinδ*cosθ;
var φ2 = Math.asin(sinφ2);
var y = sinθ * sinδ * cosφ1;
var x = cosδ - sinφ1 * sinφ2;
var λ2 = λ1 + Math.atan2(y, x);
return [toDeg(φ2), toDeg(λ2)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment