aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo
diff options
context:
space:
mode:
authorblafoo <github@blafoo.de>2012-02-23 23:13:45 +0100
committerblafoo <github@blafoo.de>2012-02-23 23:31:35 +0100
commitadfd915fa19c03b9b505a141f8c8c9658a7b5bbd (patch)
tree669202f1484acd2ae58e1e34baefb181b187e2c9 /main/src/cgeo
parent196dd6ab57977f778459ec4bb2a873b6d7734f6f (diff)
downloadcgeo-adfd915fa19c03b9b505a141f8c8c9658a7b5bbd.zip
cgeo-adfd915fa19c03b9b505a141f8c8c9658a7b5bbd.tar.gz
cgeo-adfd915fa19c03b9b505a141f8c8c9658a7b5bbd.tar.bz2
Live Map. Closes #1121
Diffstat (limited to 'main/src/cgeo')
-rw-r--r--main/src/cgeo/geocaching/GCConstants.java2
-rw-r--r--main/src/cgeo/geocaching/cgBase.java15
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCBase.java98
-rw-r--r--main/src/cgeo/geocaching/geopoint/Viewport.java8
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java2
5 files changed, 59 insertions, 66 deletions
diff --git a/main/src/cgeo/geocaching/GCConstants.java b/main/src/cgeo/geocaching/GCConstants.java
index 7134e24..fe8c74f 100644
--- a/main/src/cgeo/geocaching/GCConstants.java
+++ b/main/src/cgeo/geocaching/GCConstants.java
@@ -17,6 +17,8 @@ public final class GCConstants {
public final static String URL_LIVE_MAP = "http://www.geocaching.com/map/default.aspx";
/** Caches in a tile */
public final static String URL_MAP_INFO = "http://www.geocaching.com/map/map.info";
+ /** Tile itself */
+ public final static String URL_MAP_TILE = "http://www.geocaching.com/map/map.tile";
/**
* Patterns for parsing the result of a (detailed) search
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java
index 9a828d7..ed04c7a 100644
--- a/main/src/cgeo/geocaching/cgBase.java
+++ b/main/src/cgeo/geocaching/cgBase.java
@@ -1909,12 +1909,23 @@ public class cgBase {
return search;
}
- public static String requestJSON(final String url, final String referer) {
+ /** Request .png image for a tile. Ignore the image - just load it */
+ public static void requestMapTile(final String url, final String referer) {
final HttpGet request = new HttpGet(url);
- request.addHeader("Content-Type", "application/json; charset=UTF-8");
+ request.addHeader("Accept", "image/png,image/*;q=0.8,*/*;q=0.5");
+ request.addHeader("Accept-Encoding", "gzip, deflate");
+ request.addHeader("Referer", referer);
request.addHeader("X-Requested-With", "XMLHttpRequest");
+ request(request);
+ }
+
+ /** Request JSON informations for a tile */
+ public static String requestMapInfo(final String url, final String referer) {
+ final HttpGet request = new HttpGet(url);
request.addHeader("Accept", "application/json, text/javascript, */*; q=0.01");
+ // NO request.addHeader("Accept-Encoding", "gzip deflate");
request.addHeader("Referer", referer);
+ request.addHeader("X-Requested-With", "XMLHttpRequest");
return getResponseData(request(request), false);
}
diff --git a/main/src/cgeo/geocaching/connector/gc/GCBase.java b/main/src/cgeo/geocaching/connector/gc/GCBase.java
index 587f81b..8f6262e 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCBase.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCBase.java
@@ -52,47 +52,48 @@ public class GCBase {
* @return
*/
@SuppressWarnings("null")
- public static SearchResult searchByViewport(final Viewport viewport, final int zoomlevel, final boolean autoAdjust, String[] tokens) {
+ public static SearchResult searchByViewport(final Viewport viewport, final String[] tokens) {
- assert zoomlevel >= Tile.ZOOMLEVEL_MIN && zoomlevel <= Tile.ZOOMLEVEL_MAX : "zoomlevel out of bounds.";
-
- // TODO Ignore tokens. They are not enough. Also "&_=xxxx" is needed !
- tokens = null;
-
- Geopoint centerOfViewport = new Geopoint((viewport.getLatitudeMin() + viewport.getLatitudeMax()) / 2, (viewport.getLongitudeMin() + viewport.getLongitudeMax()) / 2);
- final String referer = GCConstants.URL_LIVE_MAP +
- "?ll=" + centerOfViewport.getLatitude() +
- "," + centerOfViewport.getLongitude();
+ String referer = GCConstants.URL_LIVE_MAP;
final SearchResult searchResult = new SearchResult();
- searchResult.setUrl(referer);
+ searchResult.setUrl(referer + "?ll=" + viewport.getCenter().getLatitude() + "," + viewport.getCenter().getLongitude());
- List<Tile> tiles = getTilesForViewport(viewport, zoomlevel, autoAdjust);
+ List<Tile> tiles = getTilesForViewport(viewport);
for (Tile tile : tiles) {
+ String url =
+ "?x=" + tile.getX() + // x tile
+ "&y=" + tile.getY() + // y tile
+ "&z=" + tile.getZoomlevel(); // zoom level
/*
- * http://www.geocaching.com/map/ --- map-url
- * map.info? --- request for JSON
- * x=8634 --- x-tile
- * y=5381 --- y-tile
- * z=14 --- zoom
- * k=xxxx --- user session
- * st=xx...xxx --- session token
- * ep=1 --- ???
- * _=1329484185663 --- timestamp (?)
+ * if (tokens != null) {
+ * url += "&k=" + tokens[0]; // user session
+ * url += "&st=" + tokens[1]; // session token
+ * }
+ * url += "&ep=1";
+ * /*
+ * if (true || Settings.isExcludeMyCaches()) {
+ * url += "&hf=1"; // hide found
+ * url += "&hh=1"; // hide hidden
+ * }
+ *
+ * if (Settings.getCacheType() == CacheType.TRADITIONAL) {
+ * url += "&ect=9,5,3,6,453,13,1304,137,11,4,8,1858"; // 2 = tradi 3 = multi 8 = mystery
+ * }
+ * if (Settings.getCacheType() == CacheType.MULTI) {
+ * url += "&ect=9,5,2,6,453,13,1304,137,11,4,8,1858";
+ * }
+ * if (Settings.getCacheType() == CacheType.MYSTERY) {
+ * url += "&ect=9,5,3,6,453,13,1304,137,11,4,2,1858";
+ * }
*/
- String url = GCConstants.URL_MAP_INFO +
- "?x=" + tile.getX() +
- "&y=" + tile.getY() +
- "&z=" + tile.getZoomlevel();
- if (tokens != null) {
- url += "&k=" + tokens[0];
- url += "&st=" + tokens[1];
+ if (tile.getZoomlevel() != 14) {
+ url += "&_=" + String.valueOf(System.currentTimeMillis());
}
- // url += "&ep=1";
- // url += "&_1329943867982";
- String data = cgBase.requestJSON(url, referer);
+ cgBase.requestMapTile(GCConstants.URL_MAP_TILE + url, referer);
+ String data = cgBase.requestMapInfo(GCConstants.URL_MAP_INFO + url, referer);
if (StringUtils.isEmpty(data)) {
Log.e(Settings.tag, "GCBase.searchByViewport: No data from server for tile (" + tile.getX() + "/" + tile.getY() + ")");
} else {
@@ -104,8 +105,6 @@ public class GCBase {
}
}
- // we don't have enough informations about the caches to do a filtering
- // final SearchResult search = searchResult.filterSearchResults(Settings.isExcludeDisabledCaches(), Settings.isExcludeMyCaches(), Settings.getCacheType(), StoredList.TEMPORARY_LIST_ID);
return searchResult;
}
@@ -236,37 +235,10 @@ public class GCBase {
* @param viewport
* @return
*/
- protected static List<Tile> getTilesForViewport(final Viewport viewport, final int zoomlevel, final boolean autoAdjust) {
- Tile tileBottomLeft = new Tile(viewport.bottomLeft, zoomlevel);
- Tile tileTopRight = new Tile(viewport.topRight, zoomlevel);
-
- int minX = Math.min(tileBottomLeft.getX(), tileTopRight.getX());
- int maxX = Math.max(tileBottomLeft.getX(), tileTopRight.getX());
- int minY = Math.min(tileBottomLeft.getY(), tileTopRight.getY());
- int maxY = Math.max(tileBottomLeft.getY(), tileTopRight.getY());
-
- // The recursion is a compromise between number of requests and precision.
- // The smaller the zoomlevel the smaller the number of requests the more inaccurate the coords are
- // The bigger the zoomlevel the bigger the number of requests the more accurate the coords are
- // For really usable coords a zoomlevel >= 13 is required
- if (autoAdjust && zoomlevel >= Tile.ZOOMLEVEL_MIN && ((maxX - minX + 1) * (maxY - minY + 1) > 4)) {
- return getTilesForViewport(viewport, zoomlevel - 1, autoAdjust);
- }
-
+ protected static List<Tile> getTilesForViewport(final Viewport viewport) {
List<Tile> tiles = new ArrayList<Tile>();
-
- if (tileBottomLeft.getX() == tileTopRight.getX() &&
- tileBottomLeft.getY() == tileTopRight.getY()) {
- tiles.add(tileBottomLeft);
- return tiles;
- }
-
- for (int x = minX; x <= maxX; x++) {
- for (int y = minY; y <= maxY; y++) {
- tiles.add(new Tile(x, y, zoomlevel));
- }
- }
- Log.d(Settings.tag, "# tiles=" + tiles.size() + " " + minX + "/" + minY + " " + maxX + "/" + maxY);
+ tiles.add(new Tile(viewport.getCenter(), 14)); // precise coords for caches nearby
+ tiles.add(new Tile(viewport.getCenter(), 12)); // other caches around
return tiles;
}
diff --git a/main/src/cgeo/geocaching/geopoint/Viewport.java b/main/src/cgeo/geocaching/geopoint/Viewport.java
index 2b76624..981f0c8 100644
--- a/main/src/cgeo/geocaching/geopoint/Viewport.java
+++ b/main/src/cgeo/geocaching/geopoint/Viewport.java
@@ -2,15 +2,19 @@ package cgeo.geocaching.geopoint;
public class Viewport {
+ public final Geopoint center;
public final Geopoint bottomLeft;
public final Geopoint topRight;
public Viewport(final Geopoint bottomLeft, final Geopoint topRight) {
this.bottomLeft = bottomLeft;
this.topRight = topRight;
+ this.center = new Geopoint((bottomLeft.getLatitude() + topRight.getLatitude()) / 2,
+ (bottomLeft.getLongitude() + topRight.getLongitude()) / 2);
}
public Viewport(final Geopoint center, final double latSpan, final double lonSpan) {
+ this.center = center;
final double centerLat = center.getLatitude();
final double centerLon = center.getLongitude();
bottomLeft = new Geopoint(centerLat - latSpan / 2, centerLon - lonSpan / 2);
@@ -33,6 +37,10 @@ public class Viewport {
return topRight.getLongitude();
}
+ public Geopoint getCenter() {
+ return center;
+ }
+
@Override
public String toString() {
return "(" + bottomLeft.toString() + "," + topRight.toString() + ")";
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 97f5de3..434eb05 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -1276,7 +1276,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
final Viewport viewport = new Viewport(new Geopoint(latMin, lonMin), new Geopoint(latMax, lonMax));
// search = cgBase.searchByViewport(token, viewport);
- search = GCBase.searchByViewport(viewport, 14, true, tokens);
+ search = GCBase.searchByViewport(viewport, tokens);
if (search != null) {
downloaded = true;
if (search.error == StatusCode.NOT_LOGGED_IN) {