Created
April 28, 2016 12:57
-
-
Save rwoloszyn/c596364f26200f84b29adce0dbe3eda5 to your computer and use it in GitHub Desktop.
draw point in some distance betwen two geo points lat/lon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_calculateOffset: function(bearing_angle, radius){ | |
//Calculate destination point based on bearing and distance | |
//http://www.movable-type.co.uk/scripts/latlong.html | |
var d2r = L.LatLng.DEG_TO_RAD; //simple convert do radians | |
var r2d= L.LatLng.RAD_TO_DEG; //simple convert to degrees | |
var radius = radius/1500; | |
var lat = this._latlng.lat * d2r; | |
var lng = this._latlng.lng * d2r; | |
var angle = bearing_angle * d2r; | |
var R = 6372.795477598; | |
var distance = (radius/R); | |
var lat2 = Math.asin( Math.sin(lat)*Math.cos(distance) + | |
Math.cos(lat)*Math.sin(distance) * Math.cos(angle)); | |
var lon2 = lng + Math.atan2(Math.sin(angle)*Math.sin(distance)*Math.cos(lat), | |
Math.cos(distance)-Math.sin(lat)*Math.sin(lat2)); | |
return new L.latLng(lat2 * r2d,lon2 * r2d); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment