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 :: python class json serializable 
Javascript :: length of list in javascript 
Javascript :: odd even javascript 
Javascript :: twilio sms sending in express 
Javascript :: javascript loop through array backwards 
Javascript :: mongoose number bigger 
Javascript :: how to destroy a computer using javascript 
Javascript :: convert a date into timestamp in javascript 
Javascript :: angular lazy loading 
Javascript :: deploy react app 
Javascript :: javascript insert div into another div 
Javascript :: html content in jspdf 
Javascript :: how to run a bash script with node js 
Javascript :: equality operator javascript 
Javascript :: docker remove json log 
Javascript :: create empty json file python 
Javascript :: data types in javascript 
Javascript :: change text shadow javascript 
Javascript :: set cors for a react node application socket error 
Javascript :: model nodejs 
Javascript :: change on select with javascript 
Javascript :: how to use graphql api in react 
Javascript :: jquery select input 
Javascript :: button change slider value js 
Javascript :: run node.js code with python 
Javascript :: js operators 
Javascript :: Navigator operation requested with a context that does not include a Navigator. 
Javascript :: regx to accept name 
Javascript :: node js function infinite parameters 
Javascript :: what is super(props) in react 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =