how to calculate distance between two points in javascript
function distance(x1, y1, x2, y2) {
return Math.hypot(x2-x1, y2-y1)
}
how to calculate distance between two points in javascript
function distance(x1, y1, x2, y2) {
return Math.hypot(x2-x1, y2-y1)
}
calculate distance between two coordinates
static double coordinateDistance(
double lat1, double lng1, double lat2, double lng2) {
const p = 0.017453292519943295;
const c = cos;
final a = 0.5 -
c((lat2 - lat1) * p) / 2 +
c(lat1 * p) * c(lat2 * p) * (1 - c((lng2 - lng1) * p)) / 2;
return 12742 * asin(sqrt(a));
}
// calculate distance from polyline-coordinates (list of locations)
static double calculateDistance(
{@required List<Location> polylineCoordinates}) {
double _totalDistance = 0.0;
for (int i = 0; i < polylineCoordinates.length - 1; i++) {
_totalDistance += coordinateDistance(
polylineCoordinates[i].lat,
polylineCoordinates[i].lng,
polylineCoordinates[i + 1].lat,
polylineCoordinates[i + 1].lng,
);
}
// distance in KM
return _totalDistance;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us