Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

latitude longitude to km javascript

function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
  var R = 6371; // Radius of the earth in km
  var dLat = deg2rad(lat2-lat1);  // deg2rad below
  var dLon = deg2rad(lon2-lon1); 
  var a = 
    Math.sin(dLat/2) * Math.sin(dLat/2) +
    Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * 
    Math.sin(dLon/2) * Math.sin(dLon/2)
    ; 
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
  var d = R * c; // Distance in km
  return d;
}

function deg2rad(deg) {
  return deg * (Math.PI/180)
}
Comment

latitude longitude to km javascript

alert(getDistanceFromLatLonInKm(-6.2445379,106.7984982,-6.2461386,106.7940001).toFixed(1));



function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
  var R = 6371; // Radius of the earth in km
  var dLat = deg2rad(lat2-lat1);  // deg2rad below
  var dLon = deg2rad(lon2-lon1); 
  var a = 
    Math.sin(dLat/2) * Math.sin(dLat/2) +
    Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * 
    Math.sin(dLon/2) * Math.sin(dLon/2)
    ; 
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
  var d = R * c; // Distance in km
  return d;
}

function deg2rad(deg) {
  return deg * (Math.PI/180)
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript slider 
Javascript :: destructuring object 
Javascript :: timer in angular 8 
Javascript :: decrementar en java 
Javascript :: react native updating options with setoptions 
Javascript :: how to check with jquery if bootstrap modal is hidden or shown 
Javascript :: yup js at least one field required 
Javascript :: get data firebase 
Javascript :: javascript read file 
Javascript :: ERROR TypeError: By.Subject is not a constructor 
Javascript :: select class with data attribute jquery 
Javascript :: ios safari controls cover element 
Javascript :: regular expression url 
Javascript :: validate ajax nonce request wordpress 
Javascript :: super in javascript 
Javascript :: javascript reload section 
Javascript :: moment get difference between business dates 
Javascript :: send embed with webhook in JS 
Javascript :: javascript modify href attr 
Javascript :: jstree expend all node 
Javascript :: cannot read property of undefined reading create material ui 
Javascript :: how to hide api key in react 
Javascript :: cypress check element has an attribute 
Javascript :: Create Your Vue Project 
Javascript :: forward and reverse loop one by one js 
Javascript :: promises in es6 
Javascript :: python restapi use post json 
Javascript :: random number generator 
Javascript :: You are trying to create a styled element with an undefined component.You may have forgotten to import it. 
Javascript :: parse string javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =