diff options
author | Bananeweizen <Bananeweizen@gmx.de> | 2012-10-01 11:37:09 +0200 |
---|---|---|
committer | Bananeweizen <Bananeweizen@gmx.de> | 2012-10-01 11:37:09 +0200 |
commit | 1b66bcd3cd640dae12cb1a523517f086c22ffbc2 (patch) | |
tree | 4aa278b58e10428fce1e22d9251551509b3a7637 /main/src/cgeo/geocaching/connector/gc/GCParser.java | |
parent | 9bb6fe872fc839bdfe5dbbc5dfe14f00f0e37733 (diff) | |
download | cgeo-1b66bcd3cd640dae12cb1a523517f086c22ffbc2.zip cgeo-1b66bcd3cd640dae12cb1a523517f086c22ffbc2.tar.gz cgeo-1b66bcd3cd640dae12cb1a523517f086c22ffbc2.tar.bz2 |
fix #2069: Search for address fails
* in case of no results by geocoder, fall back to GC website
* address search therefore now works for non Google devices
* tested with Bluestack emulator
Diffstat (limited to 'main/src/cgeo/geocaching/connector/gc/GCParser.java')
-rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCParser.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java index 2ca505d..0c00f8f 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCParser.java +++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java @@ -862,6 +862,34 @@ public abstract class GCParser { return searchByAny(cacheType, false, showCaptcha, params); } + public static SearchResult searchByAddress(final String address, final CacheType cacheType, final boolean showCaptcha) { + if (StringUtils.isBlank(address)) { + Log.e("GCParser.searchByAddress: No address given"); + return null; + } + try { + JSONObject response = Network.requestJSON("http://www.geocaching.com/api/geocode", new Parameters("q", address)); + if (response == null) { + return null; + } + if (!StringUtils.equalsIgnoreCase(response.getString("status"), "success")) { + return null; + } + if (!response.has("data")) { + return null; + } + JSONObject data = response.getJSONObject("data"); + if (data == null) { + return null; + } + return searchByCoords(new Geopoint(data.getDouble("lat"), data.getDouble("lng")), cacheType, showCaptcha); + } catch (JSONException e) { + Log.w("GCParser.searchByAddress", e); + } + + return null; + } + public static cgTrackable searchTrackable(final String geocode, final String guid, final String id) { if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid) && StringUtils.isBlank(id)) { Log.w("GCParser.searchTrackable: No geocode nor guid nor id given"); |