aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2013-07-09 21:53:53 +0200
committerSamuel Tardieu <sam@rfc1149.net>2013-07-14 13:50:37 +0200
commitf5a8c176e160812b7350f88d7bc4d3014e3ec060 (patch)
tree3734c66adbb827fc2440b71398c6f9d7e290fcfa
parentb7a84cf3cd81526f3396735e2134771a73cbb7a7 (diff)
downloadcgeo-f5a8c176e160812b7350f88d7bc4d3014e3ec060.zip
cgeo-f5a8c176e160812b7350f88d7bc4d3014e3ec060.tar.gz
cgeo-f5a8c176e160812b7350f88d7bc4d3014e3ec060.tar.bz2
Remove elevation handling
Geocaches do not contain useful elevation information. We used to get it using Google API, but the information was not very useful because our handling of altitude was inconsistent. Also, the Google elevation API usage limits states that "the Elevation API may only be used in conjunction with displaying results on a Google map; using elevation data without displaying a map for which elevation data was requested is prohibited". This removes elevation handling completely, except in the settings to avoid getting in the way of the settings rewrite. The elevation related settings should be removed there instead when both works are merged.
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java19
-rw-r--r--main/src/cgeo/geocaching/CompassActivity.java7
-rw-r--r--main/src/cgeo/geocaching/Geocache.java13
-rw-r--r--main/src/cgeo/geocaching/IGeoData.java1
-rw-r--r--main/src/cgeo/geocaching/MainActivity.java7
-rw-r--r--main/src/cgeo/geocaching/cgData.java90
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCParser.java10
-rw-r--r--main/src/cgeo/geocaching/geopoint/Geopoint.java28
-rw-r--r--main/src/cgeo/geocaching/geopoint/Units.java12
-rw-r--r--tests/src/cgeo/geocaching/geopoint/GeopointTest.java8
-rw-r--r--tests/src/cgeo/geocaching/geopoint/UnitsTest.java33
11 files changed, 46 insertions, 182 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 1b31463..9dffeb2 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -160,24 +160,9 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
return;
}
- try {
- final StringBuilder dist = new StringBuilder();
-
- if (geo.getCoords() != null && cache != null && cache.getCoords() != null) {
- dist.append(Units.getDistanceFromKilometers(geo.getCoords().distanceTo(cache.getCoords())));
- }
-
- if (cache != null && cache.getElevation() != null) {
- if (geo.getAltitude() != 0.0) {
- final float diff = (float) (cache.getElevation() - geo.getAltitude());
- dist.append(' ').append(Units.getElevation(diff));
- }
- }
-
- cacheDistanceView.setText(dist.toString());
+ if (geo.getCoords() != null && cache != null && cache.getCoords() != null) {
+ cacheDistanceView.setText(Units.getDistanceFromKilometers(geo.getCoords().distanceTo(cache.getCoords())));
cacheDistanceView.bringToFront();
- } catch (final Exception e) {
- Log.w("Failed to update location.");
}
}
};
diff --git a/main/src/cgeo/geocaching/CompassActivity.java b/main/src/cgeo/geocaching/CompassActivity.java
index 8626173..a7e0f03 100644
--- a/main/src/cgeo/geocaching/CompassActivity.java
+++ b/main/src/cgeo/geocaching/CompassActivity.java
@@ -262,12 +262,7 @@ public class CompassActivity extends AbstractActivity {
navAccuracy.setText(null);
}
- if (geo.getAltitude() != 0.0f) {
- final String humanAlt = Units.getDistanceFromMeters((float) geo.getAltitude());
- navLocation.setText(geo.getCoords() + " | " + humanAlt);
- } else {
- navLocation.setText(geo.getCoords().toString());
- }
+ navLocation.setText(geo.getCoords().toString());
updateDistanceInfo(geo);
} else {
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index dd292f9..e6db8d5 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -86,7 +86,6 @@ public class Geocache implements ICache, IWaypoint {
private String location = null;
private Geopoint coords = null;
private boolean reliableLatLon = false;
- private Double elevation = null;
private String personalNote = null;
/**
* lazy initialized
@@ -279,9 +278,6 @@ public class Geocache implements ICache, IWaypoint {
if (coords == null) {
coords = other.coords;
}
- if (elevation == null) {
- elevation = other.elevation;
- }
// don't use StringUtils.isBlank here. Otherwise we cannot recognize a note which was deleted on GC
if (personalNote == null) {
personalNote = other.personalNote;
@@ -402,7 +398,6 @@ public class Geocache implements ICache, IWaypoint {
StringUtils.equalsIgnoreCase(cacheId, other.cacheId) &&
(direction != null ? direction.equals(other.direction) : null == other.direction) &&
(distance != null ? distance.equals(other.distance) : null == other.distance) &&
- (elevation != null ? elevation.equals(other.elevation) : null == other.elevation) &&
rating == other.rating &&
votes == other.votes &&
myVote == other.myVote &&
@@ -944,14 +939,6 @@ public class Geocache implements ICache, IWaypoint {
this.reliableLatLon = reliableLatLon;
}
- public Double getElevation() {
- return elevation;
- }
-
- public void setElevation(Double elevation) {
- this.elevation = elevation;
- }
-
public void setShortDescription(String shortdesc) {
this.shortdesc = shortdesc;
}
diff --git a/main/src/cgeo/geocaching/IGeoData.java b/main/src/cgeo/geocaching/IGeoData.java
index 252fd4f..c5ef698 100644
--- a/main/src/cgeo/geocaching/IGeoData.java
+++ b/main/src/cgeo/geocaching/IGeoData.java
@@ -13,7 +13,6 @@ public interface IGeoData {
public boolean isPseudoLocation();
public Geopoint getCoords();
- public double getAltitude();
public float getBearing();
public float getSpeed();
public float getAccuracy();
diff --git a/main/src/cgeo/geocaching/MainActivity.java b/main/src/cgeo/geocaching/MainActivity.java
index 961217f..85ebe05 100644
--- a/main/src/cgeo/geocaching/MainActivity.java
+++ b/main/src/cgeo/geocaching/MainActivity.java
@@ -541,12 +541,7 @@ public class MainActivity extends AbstractActivity {
(new ObtainAddressThread()).start();
}
} else {
- if (geo.getAltitude() != 0.0) {
- final String humanAlt = Units.getDistanceFromKilometers((float) geo.getAltitude() / 1000);
- navLocation.setText(geo.getCoords() + " | " + humanAlt);
- } else {
- navLocation.setText(geo.getCoords().toString());
- }
+ navLocation.setText(geo.getCoords().toString());
}
} else {
if (nearestView.isClickable()) {
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index 2af2f82..ead698d 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -86,29 +86,28 @@ public class cgData {
"cg_caches.terrain," + // 18
"cg_caches.latlon," + // 19
"cg_caches.location," + // 20
- "cg_caches.elevation," + // 21
- "cg_caches.personal_note," + // 22
- "cg_caches.shortdesc," + // 23
- "cg_caches.favourite_cnt," + // 24
- "cg_caches.rating," + // 25
- "cg_caches.votes," + // 26
- "cg_caches.myvote," + // 27
- "cg_caches.disabled," + // 28
- "cg_caches.archived," + // 29
- "cg_caches.members," + // 30
- "cg_caches.found," + // 31
- "cg_caches.favourite," + // 32
- "cg_caches.inventoryunknown," + // 33
- "cg_caches.onWatchlist," + // 34
- "cg_caches.reliable_latlon," + // 35
- "cg_caches.coordsChanged," + // 36
- "cg_caches.latitude," + // 37
- "cg_caches.longitude," + // 38
- "cg_caches.finalDefined," + // 39
- "cg_caches._id," + // 40
- "cg_caches.inventorycoins," + // 41
- "cg_caches.inventorytags," + // 42
- "cg_caches.logPasswordRequired"; // 43
+ "cg_caches.personal_note," + // 21
+ "cg_caches.shortdesc," + // 22
+ "cg_caches.favourite_cnt," + // 23
+ "cg_caches.rating," + // 24
+ "cg_caches.votes," + // 25
+ "cg_caches.myvote," + // 26
+ "cg_caches.disabled," + // 27
+ "cg_caches.archived," + // 28
+ "cg_caches.members," + // 29
+ "cg_caches.found," + // 30
+ "cg_caches.favourite," + // 31
+ "cg_caches.inventoryunknown," + // 32
+ "cg_caches.onWatchlist," + // 33
+ "cg_caches.reliable_latlon," + // 34
+ "cg_caches.coordsChanged," + // 35
+ "cg_caches.latitude," + // 36
+ "cg_caches.longitude," + // 37
+ "cg_caches.finalDefined," + // 38
+ "cg_caches._id," + // 39
+ "cg_caches.inventorycoins," + // 40
+ "cg_caches.inventorytags," + // 41
+ "cg_caches.logPasswordRequired"; // 42
//TODO: remove "latlon" field from cache table
@@ -164,7 +163,6 @@ public class cgData {
+ "latitude double, "
+ "longitude double, "
+ "reliable_latlon integer, "
- + "elevation double, "
+ "personal_note text, "
+ "shortdesc text, "
+ "description text, "
@@ -580,7 +578,6 @@ public class cgData {
+ "latitude double, "
+ "longitude double, "
+ "reliable_latlon integer, "
- + "elevation double, "
+ "personal_note text, "
+ "shortdesc text, "
+ "description text, "
@@ -601,7 +598,7 @@ public class cgData {
db.execSQL(dbCreateCachesTemp);
db.execSQL("insert into " + dbTableCachesTemp + " select _id,updated,detailed,detailedupdate,visiteddate,geocode,reason,cacheid,guid,type,name,own,owner,owner_real," +
- "hidden,hint,size,difficulty,terrain,latlon,location,direction,distance,latitude,longitude, 0,elevation," +
+ "hidden,hint,size,difficulty,terrain,latlon,location,direction,distance,latitude,longitude, 0," +
"personal_note,shortdesc,description,favourite_cnt,rating,votes,myvote,disabled,archived,members,found,favourite,inventorycoins," +
"inventorytags,inventoryunknown,onWatchlist from " + dbTableCaches);
db.execSQL("drop table " + dbTableCaches);
@@ -1082,7 +1079,6 @@ public class cgData {
values.put("direction", cache.getDirection());
putCoords(values, cache.getCoords());
values.put("reliable_latlon", cache.isReliableLatLon() ? 1 : 0);
- values.put("elevation", cache.getElevation());
values.put("shortdesc", cache.getShortDescription());
values.put("personal_note", cache.getPersonalNote());
values.put("description", cache.getDescription());
@@ -1656,31 +1652,25 @@ public class cgData {
}
cache.setTerrain(cursor.getFloat(18));
// do not set cache.location
- cache.setCoords(getCoords(cursor, 37, 38));
- index = 21;
- if (cursor.isNull(index)) {
- cache.setElevation(null);
- } else {
- cache.setElevation(cursor.getDouble(index));
- }
- cache.setPersonalNote(cursor.getString(22));
+ cache.setCoords(getCoords(cursor, 36, 37));
+ cache.setPersonalNote(cursor.getString(21));
// do not set cache.shortdesc
// do not set cache.description
- cache.setFavoritePoints(cursor.getInt(24));
- cache.setRating(cursor.getFloat(25));
- cache.setVotes(cursor.getInt(26));
- cache.setMyVote(cursor.getFloat(27));
- cache.setDisabled(cursor.getInt(28) == 1);
- cache.setArchived(cursor.getInt(29) == 1);
- cache.setPremiumMembersOnly(cursor.getInt(30) == 1);
- cache.setFound(cursor.getInt(31) == 1);
- cache.setFavorite(cursor.getInt(32) == 1);
- cache.setInventoryItems(cursor.getInt(33));
- cache.setOnWatchlist(cursor.getInt(34) == 1);
- cache.setReliableLatLon(cursor.getInt(35) > 0);
- cache.setUserModifiedCoords(cursor.getInt(36) > 0);
- cache.setFinalDefined(cursor.getInt(39) > 0);
- cache.setLogPasswordRequired(cursor.getInt(43) > 0);
+ cache.setFavoritePoints(cursor.getInt(23));
+ cache.setRating(cursor.getFloat(24));
+ cache.setVotes(cursor.getInt(25));
+ cache.setMyVote(cursor.getFloat(26));
+ cache.setDisabled(cursor.getInt(27) == 1);
+ cache.setArchived(cursor.getInt(28) == 1);
+ cache.setPremiumMembersOnly(cursor.getInt(29) == 1);
+ cache.setFound(cursor.getInt(30) == 1);
+ cache.setFavorite(cursor.getInt(31) == 1);
+ cache.setInventoryItems(cursor.getInt(32));
+ cache.setOnWatchlist(cursor.getInt(33) == 1);
+ cache.setReliableLatLon(cursor.getInt(34) > 0);
+ cache.setUserModifiedCoords(cursor.getInt(35) > 0);
+ cache.setFinalDefined(cursor.getInt(38) > 0);
+ cache.setLogPasswordRequired(cursor.getInt(42) > 0);
Log.d("Loading " + cache.toString() + " (" + cache.getListId() + ") from DB");
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java
index ea15633..9ecb51b 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCParser.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -1756,16 +1756,6 @@ public abstract class GCParser {
}
}
- if (Settings.isElevationWanted()) {
- if (CancellableHandler.isCancelled(handler)) {
- return;
- }
- CancellableHandler.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_elevation);
- if (cache.getCoords() != null) {
- cache.setElevation(cache.getCoords().getElevation());
- }
- }
-
if (Settings.isRatingWanted()) {
if (CancellableHandler.isCancelled(handler)) {
return;
diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java
index 1973b03..11f03cb 100644
--- a/main/src/cgeo/geocaching/geopoint/Geopoint.java
+++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java
@@ -323,34 +323,6 @@ public final class Geopoint implements ICoordinates, Parcelable {
}
}
- public Double getElevation() {
- try {
- final String uri = "http://maps.googleapis.com/maps/api/elevation/json";
- final Parameters params = new Parameters(
- "sensor", "false",
- "locations", format(Format.LAT_LON_DECDEGREE_COMMA));
- final JSONObject response = Network.requestJSON(uri, params);
-
- if (response == null) {
- return null;
- }
-
- if (!StringUtils.equalsIgnoreCase(response.getString("status"), "OK")) {
- return null;
- }
-
- if (response.has("results")) {
- JSONArray results = response.getJSONArray("results");
- JSONObject result = results.getJSONObject(0);
- return result.getDouble("elevation");
- }
- } catch (Exception e) {
- Log.w("Geopoint.getElevation", e);
- }
-
- return null;
- }
-
@Override
public Geopoint getCoords() {
return this;
diff --git a/main/src/cgeo/geocaching/geopoint/Units.java b/main/src/cgeo/geocaching/geopoint/Units.java
index 75d71d0..b99e00e 100644
--- a/main/src/cgeo/geocaching/geopoint/Units.java
+++ b/main/src/cgeo/geocaching/geopoint/Units.java
@@ -47,18 +47,6 @@ public class Units {
return String.format(formatString + " %s", scaled.left, scaled.right);
}
- /**
- * Get human readable elevation, depending on settings for metric units.
- * Result is rounded to full meters/feet, as the sensors don't have that precision anyway.
- *
- * @param meters
- * @return
- */
- public static String getElevation(float meters) {
- final ImmutablePair<Double, String> scaled = scaleDistance(meters / 1000f);
- return (meters >= 0 ? "↥ " : "↧ ") + String.format("%d %s", Math.abs(Math.round(scaled.left)), scaled.right);
- }
-
public static String getDistanceFromMeters(float meters) {
return getDistanceFromKilometers(meters / 1000f);
}
diff --git a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java b/tests/src/cgeo/geocaching/geopoint/GeopointTest.java
index 8aaeef8..e64028f 100644
--- a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/GeopointTest.java
@@ -1,10 +1,10 @@
package cgeo.geocaching.geopoint;
+import junit.framework.Assert;
+
import android.os.Bundle;
import android.test.AndroidTestCase;
-import junit.framework.Assert;
-
public class GeopointTest extends AndroidTestCase {
public static void testCreation() {
@@ -230,10 +230,6 @@ public class GeopointTest extends AndroidTestCase {
Assert.assertEquals(lonSecFrac, gp.getLonSecFrac());
}
- public static void testElevation() {
- assertEquals(125.663703918457, (new Geopoint(48.0, 2.0)).getElevation(), 0.1);
- }
-
private static void assertParseException(Runnable runnable) {
try {
runnable.run();
diff --git a/tests/src/cgeo/geocaching/geopoint/UnitsTest.java b/tests/src/cgeo/geocaching/geopoint/UnitsTest.java
index 3b7331c..52c5adf 100644
--- a/tests/src/cgeo/geocaching/geopoint/UnitsTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/UnitsTest.java
@@ -42,39 +42,6 @@ public class UnitsTest extends CGeoTestCase {
// Make method non-static so that Settings is initialized
@SuppressWarnings("static-method")
- public void testElevation() {
- final boolean savedImperial = Settings.isUseImperialUnits();
- try {
- TestSettings.setUseImperialUnits(false);
- assertElevation("↥ 123 m", 122.782f);
- assertElevation("↥ 123 m", 123.456f);
- assertElevation("↥ 12 m", 12.3456f);
- assertElevation("↥ 1 m", 1.23456f);
- assertElevation("↥ 2 m", 1.6f);
- assertElevation("↥ 0 m", 0.123456f);
- assertElevation("↧ 123 m", -122.782f);
- assertElevation("↧ 123 m", -123.456f);
- assertElevation("↧ 12 m", -12.3456f);
- assertElevation("↧ 1 m", -1.23456f);
- assertElevation("↧ 2 m", -1.6f);
- assertElevation("↧ 0 m", -0.123456f);
- TestSettings.setUseImperialUnits(true);
- assertElevation("↥ 405 ft", 123.456f);
- assertElevation("↥ 41 ft", 12.3456f);
- } finally {
- TestSettings.setUseImperialUnits(savedImperial);
- }
- }
-
- private static void assertElevation(final String expected, final float meters) {
- final String actual = Units.getElevation(meters);
- if (!StringUtils.equals(expected, actual.replace(',', '.'))) {
- fail("elevation " + actual + " does not match expected " + expected);
- }
- }
-
- // Make method non-static so that Settings is initialized
- @SuppressWarnings("static-method")
public void testSpeed() {
assertEquals("?", Units.getDistanceFromKilometers(null));
final boolean savedImperial = Settings.isUseImperialUnits();