aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/cgGeo.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cgeo/geocaching/cgGeo.java')
-rw-r--r--src/cgeo/geocaching/cgGeo.java48
1 files changed, 20 insertions, 28 deletions
diff --git a/src/cgeo/geocaching/cgGeo.java b/src/cgeo/geocaching/cgGeo.java
index bcc0de1..c908580 100644
--- a/src/cgeo/geocaching/cgGeo.java
+++ b/src/cgeo/geocaching/cgGeo.java
@@ -16,6 +16,7 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
+import cgeo.geocaching.geopoint.Geopoint;
public class cgGeo {
@@ -35,14 +36,11 @@ public class cgGeo {
private Location locNet = null;
private long locGpsLast = 0L;
private boolean g4cRunning = false;
- private Double lastGo4cacheLat = null;
- private Double lastGo4cacheLon = null;
+ private Geopoint lastGo4cacheCoords = null;
public Location location = null;
public int gps = -1;
- public Double latitudeNow = null;
- public Double longitudeNow = null;
- public Double latitudeBefore = null;
- public Double longitudeBefore = null;
+ public Geopoint coordsNow = null;
+ public Geopoint coordsBefore = null;
public Double altitudeNow = null;
public Double bearingNow = null;
public Float speedNow = null;
@@ -87,8 +85,7 @@ public class cgGeo {
public void initGeo() {
location = null;
gps = -1;
- latitudeNow = null;
- longitudeNow = null;
+ coordsNow = null;
altitudeNow = null;
bearingNow = null;
speedNow = null;
@@ -284,14 +281,13 @@ public class cgGeo {
assign(locNet); // nothing else, using NET
}
- private void assign(Double lat, Double lon) {
- if (lat == null || lon == null) {
+ private void assign(final Geopoint coords) {
+ if (coords == null) {
return;
}
gps = -1;
- latitudeNow = lat;
- longitudeNow = lon;
+ coordsNow = coords;
altitudeNow = null;
bearingNow = Double.valueOf(0);
speedNow = 0f;
@@ -319,9 +315,8 @@ public class cgGeo {
gps = -1;
}
- latitudeNow = location.getLatitude();
- longitudeNow = location.getLongitude();
- app.setLastLoc(latitudeNow, longitudeNow);
+ coordsNow = new Geopoint(location.getLatitude(), location.getLongitude());
+ app.setLastLoc(coordsNow);
if (location.hasAltitude() && gps != -1) {
altitudeNow = location.getAltitude() + settings.altCorrection;
@@ -346,18 +341,16 @@ public class cgGeo {
if (gps == 1) {
// save travelled distance only when location is from GPS
- if (latitudeBefore != null && longitudeBefore != null && latitudeNow != null && longitudeNow != null) {
- final double dst = cgBase.getDistance(latitudeBefore, longitudeBefore, latitudeNow, longitudeNow);
+ if (coordsBefore != null && coordsNow != null) {
+ final double dst = cgBase.getDistance(coordsBefore, coordsNow);
if (Double.isNaN(dst) == false && dst > 0.005) {
distanceNow += dst;
- latitudeBefore = latitudeNow;
- longitudeBefore = longitudeNow;
+ coordsBefore = coordsNow;
}
- } else if (latitudeBefore == null || longitudeBefore == null) { // values aren't initialized
- latitudeBefore = latitudeNow;
- longitudeBefore = longitudeNow;
+ } else if (coordsBefore == null) { // values aren't initialized
+ coordsBefore = coordsNow;
}
}
@@ -382,7 +375,7 @@ public class cgGeo {
return;
}
- if (settings.publicLoc == 1 && (lastGo4cacheLat == null || lastGo4cacheLon == null || cgBase.getDistance(latitudeNow, longitudeNow, lastGo4cacheLat, lastGo4cacheLon) > 0.75)) {
+ if (settings.publicLoc == 1 && (lastGo4cacheCoords == null || cgBase.getDistance(coordsNow, lastGo4cacheCoords) > 0.75)) {
g4cRunning = true;
final String host = "api.go4cache.com";
@@ -398,8 +391,8 @@ public class cgGeo {
final String username = settings.getUsername();
if (username != null) {
final Map<String, String> params = new HashMap<String, String>();
- final String latStr = String.format((Locale) null, "%.6f", latitudeNow);
- final String lonStr = String.format((Locale) null, "%.6f", longitudeNow);
+ final String latStr = String.format((Locale) null, "%.6f", coordsNow.getLatitude());
+ final String lonStr = String.format((Locale) null, "%.6f", coordsNow.getLongitude());
params.put("u", username);
params.put("lt", latStr);
params.put("ln", lonStr);
@@ -411,8 +404,7 @@ public class cgGeo {
final String res = base.request(false, host, path, method, params, false, false, false).getData();
if (StringUtils.isNotBlank(res)) {
- lastGo4cacheLat = latitudeNow;
- lastGo4cacheLon = longitudeNow;
+ lastGo4cacheCoords = coordsNow;
}
}
}
@@ -422,7 +414,7 @@ public class cgGeo {
}
public void lastLoc() {
- assign(app.getLastLat(), app.getLastLon());
+ assign(app.getLastCoords());
Location lastGps = geoManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);