Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

latitude and longitude distance calculate in node js

// npm i geolib

const { getDistance } = require('geolib');
const distance = getDistance(
    { latitude: 51.5103, longitude: 7.49347 },
    { latitude: 51.5200, longitude: 7.49347 }
)
console.log(distance / 1000) //value in km

//$uj@y
Comment

latitude and longitude distance calculate in node js

function distance(lat1, lon1, lat2, lon2) {
	var p = 0.017453292519943295;    // Math.PI / 180
	var c = Math.cos;
	var a = 0.5 - c((lat2 - lat1) * p)/2 + 
			c(lat1 * p) * c(lat2 * p) * 
			(1 - c((lon2 - lon1) * p))/2;
  
	return 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km
}
console.log(distance(51.5103, 7.49347, 51.5200, 7.49347))

//$uj@y
Comment

latitude and longitude distance calculate in node js

//npm i geopoint
const GeoPoint = require('geopoint');
point1 = new GeoPoint(51.5103, 7.49347);
point2 = new GeoPoint(51.5200, 7.49347);
var distance = point1.distanceTo(point2, true)//output in kilometers
console.log(distance)

//$uj@y
Comment

PREVIOUS NEXT
Code Example
Javascript :: body click function removeclass 
Javascript :: order array of objects by id javascript 
Javascript :: reset redux form after validation 
Javascript :: eject expo app to android and react native 
Javascript :: cypress click 
Javascript :: Vuejs watch for nested data 
Javascript :: how to edit website in browser using javascript on google chrome 
Javascript :: reactjs javascript is mobile and desktop 
Javascript :: console log in vue 
Javascript :: javascript object to base64 
Javascript :: Install react router in react app 
Javascript :: How to swap two array elements in JavaScript 
Javascript :: error while connecting mongodb MongoParseError: option usefindandmodify is not supported 
Javascript :: discord.js find role by name 
Javascript :: how to include in ejs 
Javascript :: how to pass state values as initial data and support state updates for Formik while using useFormik hook 
Javascript :: iterate through list javascript 
Javascript :: how to get element of an array in javascript 
Javascript :: invert binary tree javascript 
Javascript :: mongoose findoneandupdate 
Javascript :: send refresh token in axios interceptor 
Javascript :: delete cookies by domain javascript 
Javascript :: credit card regex 
Javascript :: jquery select element with two classes 
Javascript :: react import css only for component 
Javascript :: pagination hook react 
Javascript :: login page link shopify 
Javascript :: javascript remove underscore and capitalize 
Javascript :: find Array of value in JSON 
Javascript :: REACT-ICONS reduce thickness 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =