added navigation to location from map

This commit is contained in:
Sem van der Hoeven
2021-01-05 16:02:48 +01:00
parent 16bd30f785
commit 062739ac7b
4 changed files with 95 additions and 24 deletions

View File

@@ -108,6 +108,25 @@ public class Location implements Parcelable {
return long1 + "," + lat1;
}
public double getDistance(Location other) {
double dlon = other.getLong() - getLong();
double dlat = other.getLat() - getLong();
double a = Math.pow(Math.sin(dlat / 2), 2)
+ Math.cos(getLat()) * Math.cos(other.getLong())
* Math.pow(Math.sin(dlon / 2),2);
double c = 2 * Math.asin(Math.sqrt(a));
// Radius of earth in kilometers. Use 3956
// for miles
double r = 6371;
// calculate the result
double distance = c * r;
return Math.floor(distance);
}
public GeoPoint convertToGeoPoint() {
return new GeoPoint(this.getLat(),this.getLong());
}

View File

@@ -2,8 +2,20 @@ package com.a1.nextlocation.data;
import org.osmdroid.views.overlay.Polyline;
public enum CurrentRoute {
/**
* singleton to keep track of different global data
*/
public enum StaticData {
INSTANCE;
private double distanceTraveled = 0;
public void addDistance(double d) {
distanceTraveled += d;
}
public double getDistanceTraveled() {
return distanceTraveled;
}
private Polyline currentRoute;