You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Joe Bowser (JIRA)" <ji...@apache.org> on 2013/04/17 22:39:17 UTC

[jira] [Updated] (CB-2273) There is a bug in the android geolocation plugin of Cordova 2.3

     [ https://issues.apache.org/jira/browse/CB-2273?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joe Bowser updated CB-2273:
---------------------------

    Fix Version/s: 2.7.0
    
> There is a bug in the android geolocation plugin of Cordova 2.3
> ---------------------------------------------------------------
>
>                 Key: CB-2273
>                 URL: https://issues.apache.org/jira/browse/CB-2273
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 2.2.0, 2.3.0
>         Environment: HTC t328D,Android 4.0.3
>            Reporter: SunshineTech Zhang
>            Assignee: Joe Bowser
>              Labels: patch
>             Fix For: 2.7.0
>
>
> When I call the watchPosition function, it only call back my successCallback function 2 times and errorCallback function once. That is, it call back successCallback function of getCurrentPosition and watchPosition; and errorCallback function of watchPosition when timeout event was fired. Then the plugin gives nothing any more.
> Then I read the source code of org.apache.cordova.GeoBroker and org.apache.cordova.CordovaLocationListener. I found there was an issue in the win and fail method of org.apache.cordova.CordovaLocationListener. That is, after the listener called its callbacks' by traversal, it then stop itself, so it doesn't listen position changed information for its watches list.
> So I modify them, the plugin runs well.
> 1. I modify the win and fail method in the org.apache.cordova.CordovaLocationListener as the following:
> protected void fail(int code, String message) {
>         for (CallbackContext callbackContext: this.callbacks)
>         {
>             this.owner.fail(code, message, callbackContext, false);
>         }
>         if(this.owner.isGlobalListener(this) && this.watches.size() == 0)
>         {
>         	Log.d(TAG, "Stopping global listener");
>         	this.stop();
>         }
>         this.callbacks.clear();
>         Iterator<CallbackContext> it = this.watches.values().iterator();
>         while (it.hasNext()) {
>             this.owner.fail(code, message, it.next(), true);
>         }
>     }
>     private void win(Location loc) {
>         for (CallbackContext callbackContext: this.callbacks)
>         {
>             this.owner.win(loc, callbackContext, false);
>         }
>         if(this.owner.isGlobalListener(this) && this.watches.size() == 0)
>         {
>         	Log.d(TAG, "Stopping global listener");
>         	this.stop();
>         }
>         this.callbacks.clear();
>         Iterator<CallbackContext> it = this.watches.values().iterator();
>         while (it.hasNext()) {
>             this.owner.win(loc, it.next(), true);
>         }
>     }
> 2、I modify the win and fail method in the org.apache.cordova.GeoBroker as the following:
> public void win(Location loc, CallbackContext callbackContext, boolean keepCallback) {
>     	PluginResult result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(loc));
>     	result.setKeepCallback(keepCallback);
>         callbackContext.sendPluginResult(result);
> }
> public void fail(int code, String msg, CallbackContext callbackContext, boolean keepCallback) {
>         JSONObject obj = new JSONObject();
>         String backup = null;
>         try {
>             obj.put("code", code);
>             obj.put("message", msg);
>         } catch (JSONException e) {
>             obj = null;
>             backup = "{'code':" + code + ",'message':'" + msg.replaceAll("'", "\'") + "'}";
>         }
>         PluginResult result;
>         if (obj != null) {
>             result = new PluginResult(PluginResult.Status.ERROR, obj);
>         } else {
>             result = new PluginResult(PluginResult.Status.ERROR, backup);
>         }
>         result.setKeepCallback(keepCallback);
>         callbackContext.sendPluginResult(result);
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira