aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/geopoint
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2012-03-10 07:37:59 +0100
committerBananeweizen <bananeweizen@gmx.de>2012-03-10 07:37:59 +0100
commitb297de18e81872e9725867ba4da4a9481aedfcbf (patch)
tree80db5404f602577fdbf2d3e1bb34c36f850300d2 /main/src/cgeo/geocaching/geopoint
parent5daaa3d454ff680e74fdbf8f673674d0eb339817 (diff)
downloadcgeo-b297de18e81872e9725867ba4da4a9481aedfcbf.zip
cgeo-b297de18e81872e9725867ba4da4a9481aedfcbf.tar.gz
cgeo-b297de18e81872e9725867ba4da4a9481aedfcbf.tar.bz2
refactoring: first part of removing cgBase
* extract network stuff (non GC related) * extract GC login stuff * move UI related pieces to activities * to do: move parsing and searching to better places, remove cgBase completely afterwards
Diffstat (limited to 'main/src/cgeo/geocaching/geopoint')
-rw-r--r--main/src/cgeo/geocaching/geopoint/Geopoint.java39
1 files changed, 38 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java
index ca67014..fdcc663 100644
--- a/main/src/cgeo/geocaching/geopoint/Geopoint.java
+++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java
@@ -1,8 +1,16 @@
package cgeo.geocaching.geopoint;
+import cgeo.geocaching.Settings;
+import cgeo.geocaching.geopoint.GeopointFormatter.Format;
+import cgeo.geocaching.network.Network;
+import cgeo.geocaching.network.Parameters;
+
import org.apache.commons.lang3.StringUtils;
+import org.json.JSONArray;
+import org.json.JSONObject;
import android.location.Location;
+import android.util.Log;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -234,7 +242,7 @@ public final class Geopoint
/**
* Returns formatted coordinates with default format.
* Default format is decimalminutes, e.g. N 52° 36.123 E 010° 03.456
- *
+ *
* @return formatted coordinates
*/
@Override
@@ -475,4 +483,33 @@ public final class Geopoint
super(msg);
}
}
+
+ 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(Settings.tag, "cgBase.getElevation: " + e.toString());
+ }
+
+ return null;
+ }
+
}