Skip to content

Commit

Permalink
Merge pull request #2700 from pingwang2011/timob-10309
Browse files Browse the repository at this point in the history
Timob 10309: Android: Ti.Geolocation.forwardGeocoder() callback is not called for a bad address
  • Loading branch information
ayeung committed Aug 10, 2012
2 parents 1683081 + 1b18ad8 commit f682e7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ private AsyncTask<Object, Void, Integer> getLookUpTask()
AsyncTask<Object, Void, Integer> task = new AsyncTask<Object, Void, Integer>() {
@Override
protected Integer doInBackground(Object... args) {
GeocodeResponseHandler geocodeResponseHandler = null;
HashMap<String, Object> event = null;
try {
String url = (String) args[0];
String direction = (String) args[1];
GeocodeResponseHandler geocodeResponseHandler = (GeocodeResponseHandler) args[2];
geocodeResponseHandler = (GeocodeResponseHandler) args[2];

Log.d(TAG, "GEO URL [" + url + "]", Log.DEBUG_MODE);
HttpGet httpGet = new HttpGet(url);
Expand All @@ -241,7 +243,6 @@ protected Integer doInBackground(Object... args) {

Log.i(TAG, "received Geo [" + response + "]", Log.DEBUG_MODE);

HashMap<String, Object> event = null;
if (response != null) {
try {
JSONObject jsonObject = new JSONObject(response);
Expand All @@ -255,24 +256,26 @@ protected Integer doInBackground(Object... args) {

} else {
event = new KrollDict();
KrollDict errorDict = new KrollDict();
String errorCode = jsonObject.getString(TiC.ERROR_PROPERTY_ERRORCODE);
errorDict.put(TiC.PROPERTY_MESSAGE, "Unable to resolve message: Code (" + errorCode + ")");
errorDict.put(TiC.PROPERTY_CODE, errorCode);
event.put(TiC.EVENT_PROPERTY_ERROR, errorDict);
event.put(TiC.EVENT_PROPERTY_ERROR, "Unable to resolve message: Code (" + errorCode + ")");
}

} catch (JSONException e) {
Log.e(TAG, "Error converting geo response to JSONObject [" + e.getMessage() + "]", e);
Log.e(TAG, "Error converting geo response to JSONObject [" + e.getMessage() + "]", e, Log.DEBUG_MODE);
}
}

if (event != null) {
geocodeResponseHandler.handleGeocodeResponse(event);
}

} catch (Throwable t) {
Log.e(TAG, "Error retrieving geocode information [" + t.getMessage() + "]", t);
Log.e(TAG, "Error retrieving geocode information [" + t.getMessage() + "]", t, Log.DEBUG_MODE);
}

if (geocodeResponseHandler != null) {
if (event == null) {
event = new KrollDict();
event.put(TiC.PROPERTY_SUCCESS, false);
event.put(TiC.EVENT_PROPERTY_ERROR, "Error obtaining geolocation");
}
geocodeResponseHandler.handleGeocodeResponse(event);
}

return -1;
Expand All @@ -292,6 +295,7 @@ private HashMap<String, Object> buildForwardGeocodeResponse(JSONObject jsonRespo
address = buildAddress(places.getJSONObject(0));
}

address.put(TiC.PROPERTY_SUCCESS, true);
return address;
}

Expand Down
9 changes: 7 additions & 2 deletions apidoc/Titanium/Geolocation/Geolocation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,12 @@ properties:
- name: success
summary: Indicates whether the request succeeded.
type: Boolean
platforms: [iphone, ipad]
platforms: [android, iphone, ipad]

- name: error
summary: Error message when the request failed.
type: String
platforms: [android, iphone, ipad]

- name: accuracy
summary: Estimated accuracy of the geocoding, in meters.
Expand Down Expand Up @@ -758,7 +763,7 @@ properties:
platforms: [android]

- name: country_code
summary: Country code. Same as `country_code`.
summary: Country code. Same as `countryCode`.
type: String
platforms: [android]

Expand Down

0 comments on commit f682e7f

Please sign in to comment.