added updating location when you're close to it
This commit is contained in:
@@ -35,6 +35,10 @@ public class Location implements Parcelable {
|
||||
this(name,getStringFromCoordinates(latCoord,longCoord),description,imageUrl);
|
||||
}
|
||||
|
||||
public Location(String name, android.location.Location loc, String description, String imageUrl) {
|
||||
this(name,getStringFromCoordinates(loc.getLatitude(),loc.getLongitude()),description,imageUrl);
|
||||
}
|
||||
|
||||
protected Location(Parcel in) {
|
||||
name = in.readString();
|
||||
coordinates = in.readString();
|
||||
@@ -127,6 +131,25 @@ public class Location implements Parcelable {
|
||||
return Math.floor(distance);
|
||||
}
|
||||
|
||||
public static double getDistance(double lat1, double lon1, double lat2, double lon2) {
|
||||
double dlon = lon2 - lon1;
|
||||
double dlat = lat2 - lat1;
|
||||
double a = Math.pow(Math.sin(dlat / 2), 2)
|
||||
+ Math.cos(lat1) * Math.cos(lat2)
|
||||
* 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());
|
||||
}
|
||||
|
||||
@@ -2,21 +2,38 @@ package com.a1.nextlocation.data;
|
||||
|
||||
import org.osmdroid.views.overlay.Polyline;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* singleton to keep track of different global data
|
||||
*/
|
||||
public enum StaticData {
|
||||
INSTANCE;
|
||||
private double distanceTraveled = 0;
|
||||
private int locationsVisited = 0;
|
||||
|
||||
private ArrayList<String> visitedNames = new ArrayList<>();
|
||||
|
||||
public void addDistance(double d) {
|
||||
distanceTraveled += d;
|
||||
}
|
||||
|
||||
|
||||
public double getDistanceTraveled() {
|
||||
return distanceTraveled;
|
||||
}
|
||||
|
||||
public void visitLocation(Location location) {
|
||||
if (!visitedNames.contains(location.getName())) {
|
||||
locationsVisited++;
|
||||
visitedNames.add(location.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public int getLocationsVisited() {
|
||||
return locationsVisited;
|
||||
}
|
||||
|
||||
private Polyline currentRoute;
|
||||
|
||||
public void setCurrentRoute(Polyline currentRoute) {
|
||||
|
||||
Reference in New Issue
Block a user