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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user