Javascript how to add a radius to latitude and longitude
Javascript how to add a radius to latitude and longitude
I have a javascript function to calculate the distance between two coordinates. Now, I need to create another function that takes in a gps coordinates and add a radius to come up with a 2nd coordinates. I'm not sure how to do that and the math behind it.
Here's the function for calculating the distance between two coordinates.
function distanceInKm(lat1, lon1, lat2, lon2) {
var earthRadiusKm = 6371;
var dLat = degreesToRadians(lat2-lat1);
var dLon = degreesToRadians(lon2-lon1);
lat1 = degreesToRadians(lat1);
lat2 = degreesToRadians(lat2);
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return earthRadiusKm * c;
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment