calculate distance between two coordinates formula javascript
JavaScript
alert(calcCrow(59.3293371,13.4877472,59.3225525,13.4619422).toFixed(1));
//This function takes in latitude and longitude of two location and returns the distance between them as the crow flies (in km)
function calcCrow(lat1, lon1, lat2, lon2)
{
var R = 6371; // km
var dLat = toRad(lat2-lat1);
var dLon = toRad(lon2-lon1);
var lat1 = toRad(lat1);
var lat2 = toRad(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));
var d = R * c;
return d;
}
// Converts numeric degrees to radians
function toRad(Value)
{
return Value * Math.PI / 180;
}
Also in JavaScript:
- Title
- how to expire a cookie in javascript
- Category
- JavaScript
- Title
- defineCall is not a function at Sequelize.import sequelize.js
- Category
- JavaScript
- Title
- get client timezone offset JavaScript
- Category
- JavaScript
- Title
- flatten nested array javascript
- Category
- JavaScript
- Title
- function increase a number by click javascript
- Category
- JavaScript
- Title
- get contents between tags javascript
- Category
- JavaScript
- Title
- cdn react
- Category
- JavaScript
- Title
- checkbox click event jquery
- Category
- JavaScript
- Title
- email regex javscript
- Category
- JavaScript
- Title
- going through every attributes of an object javascript
- Category
- JavaScript
- Title
- args discord.js
- Category
- JavaScript
- Title
- foreach javascript
- Category
- JavaScript
- Title
- get query string javascript nodejs
- Category
- JavaScript
- Title
- how to create uuid in javascript
- Category
- JavaScript
- Title
- array every javascript
- Category
- JavaScript
- Title
- javascript check if number is hexadecimal
- Category
- JavaScript
- Title
- command to create react app
- Category
- JavaScript
- Title
- how to move a block in javascript
- Category
- JavaScript
- Title
- how to make fake binary
- Category
- JavaScript
- Title
- evaluation of postfix expression using stack in c
- Category
- JavaScript
- Title
- how to add data-toggle and data-target using jquery
- Category
- JavaScript
- Title
- how to use a js class in react
- Category
- JavaScript
- Title
- javascript change page title
- Category
- JavaScript
- Title
- elasticsearch test node.js
- Category
- JavaScript
- Title
- how to convert array to uppercase in javascript
- Category
- JavaScript
- Title
- integer to array javascript
- Category
- JavaScript
- Title
- install vue-cli
- Category
- JavaScript
- Title
- javascript audio stop
- Category
- JavaScript
- Title
- javascript change url hash
- Category
- JavaScript
- Title
- window location in react
- Category
- JavaScript
- Title
- how to get user ip address in javascript
- Category
- JavaScript
- Title
- angular interview questions
- Category
- JavaScript
- Title
- defer parsing of javascript wordpress
- Category
- JavaScript
- Title
- choose random from array javascript
- Category
- JavaScript
- Title
- how to calculate balance automatically using javascript and php using cash paid
- Category
- JavaScript
- Title
- email validation regex
- Category
- JavaScript
- Title
- angular 6 reload current page
- Category
- JavaScript
- Title
- how to create simple node project
- Category
- JavaScript
- Title
- how to set text for label in jquery
- Category
- JavaScript
- Title
- chart js rotating the x axis labels
- Category
- JavaScript
- Title
- change src of iframe jquery
- Category
- JavaScript
- Title
- create react app in existing folder
- Category
- JavaScript
- Title
- jalali moment get milisocnds
- Category
- JavaScript
- Title
- javascript check if date is today
- Category
- JavaScript
- Title
- array meses javascript
- Category
- JavaScript
- Title
- how to make a div scrollable
- Category
- JavaScript
- Title
- how to contain image size
- Category
- JavaScript
- Title
- how to append object in array javascript
- Category
- JavaScript
- Title
- angular random number between 1 and 10
- Category
- JavaScript
- Title
- how to capitalize a letter based on an index in javascript
- Category
- JavaScript
- Title
- How can I upload files asynchronously
- Category
- JavaScript
- Title
- arrow function javascript ie11
- Category
- JavaScript
- Title
- check if word has accented or unaccented javascript
- Category
- JavaScript
- Title
- how to appendChild in the begin of the div javascript
- Category
- JavaScript
- Title
- find the last occurrence of a character in a string javascript
- Category
- JavaScript
- Title
- how to displayan inteiger to a tenth in javascript
- Category
- JavaScript
- Title
- javascript check if undefined or null
- Category
- JavaScript
- Title
- discord.js tagging the author
- Category
- JavaScript
- Title
- A cookie associated with a cross-site resource at http://placeholder.com/ was set without the `SameSite` attribute.
- Category
- JavaScript
- Title
- javascript click event notifications
- Category
- JavaScript
- Title
- add dynamic value to id attribute in angular 8
- Category
- JavaScript
- Title
- copy to clipboard function javascript
- Category
- JavaScript
- Title
- conditional chaining chrome
- Category
- JavaScript
- Title
- javascript check if string is json parsable
- Category
- JavaScript
- Title
- clear the console while in strict mode
- Category
- JavaScript
- Title
- how to loop audio in js
- Category
- JavaScript
- Title
- how to get a variable from php to javascript
- Category
- JavaScript
- Title
- javascript are arrays equal
- Category
- JavaScript
- Title
- crypto.com api
- Category
- JavaScript
- Title
- how to draw a horizontal line in javascript
- Category
- JavaScript
- Title
- angular directive example
- Category
- JavaScript
- Title
- html decode javascript
- Category
- JavaScript
- Title
- javascript array contains object
- Category
- JavaScript
- Title
- binary to int javascript
- Category
- JavaScript
- Title
- discord.js how to go back a file
- Category
- JavaScript
- Title
- declarar una funcion javascript
- Category
- JavaScript
- Title
- how to deep copy object in javascript
- Category
- JavaScript
- Title
- how to get binary value of int javascript
- Category
- JavaScript
- Title
- how to javascript
- Category
- JavaScript
- Title
- javascript check if in array
- Category
- JavaScript
- Title
- how to make a random number guessing game in javascript
- Category
- JavaScript
- Title
- how to write regular expression
- Category
- JavaScript
- Title
- javascript array group by id
- Category
- JavaScript
- Title
- add a slash to string in javascript
- Category
- JavaScript
- Title
- get id of clicked element javascript
- Category
- JavaScript
- Title
- how to import jquery in js file
- Category
- JavaScript
- Title
- javascript check if undefined or null or empty string
- Category
- JavaScript
- Title
- how to use ternary operatiion in sequelize join statement
- Category
- JavaScript
- Title
- how to get variable in local storage in javascript
- Category
- JavaScript
- Title
- change style on click react
- Category
- JavaScript
- Title
- how to add object to list in javascript
- Category
- JavaScript
- Title
- href before onclick js
- Category
- JavaScript
- Title
- email validation in javascript
- Category
- JavaScript
- Title
- how to get selected row index of table in javascript
- Category
- JavaScript
- Title
- javascript base64 encode string
- Category
- JavaScript
- Title
- create a customer in stripe node.js
- Category
- JavaScript
- Title
- how to add two number using jqueryu
- Category
- JavaScript
- Title
- how to set state when change viewport react
- Category
- JavaScript
- Title
- javascript .split().reverse.join
- Category
- JavaScript
- Title
- (node:3168) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead. (Use `node --trace-deprecation ...` to show where the warning was created)
- Category
- JavaScript