Thanks, Please file an issue at http://issues.cordova.io - this mailing list is for the discussion of the development of the Cordova API only.
On Sun, Jan 20, 2013 at 10:31 PM, 张雪魂 <zhangxue...@gmail.com> wrote: > When I call the watchPosition function, it only call back > my successCallback function 2 times and errorCallback function once. That > is, It only fires timeout event once. Then the plugin doesn't give to me > the position. I read the plugin source, I think there are some problems. > Then I modify them, the plugin runs well. > 1、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); > } > > 2、I modify the win and fail method in > the org.apache.cordova.CordovaLocationListener as the following: > > private void win(Location loc) { > for (CallbackContext callbackContext: this.callbacks) > { > this.owner.win(loc, callbackContext, false); > } > this.callbacks.clear(); > > if(this.owner.isGlobalListener(this) && this.size() == 0) > { > Log.d(TAG, "Stopping global listener"); > this.stop(); > } > Iterator<CallbackContext> it = this.watches.values().iterator(); > while (it.hasNext()) { > this.owner.win(loc, it.next(), true); > } > } > > protected void fail(int code, String message) { > for (CallbackContext callbackContext: this.callbacks) > { > this.owner.fail(code, message, callbackContext, false); > } > this.callbacks.clear(); > > if(this.owner.isGlobalListener(this) && this.size() == 0) > { > Log.d(TAG, "Stopping global listener"); > this.stop(); > } > Iterator<CallbackContext> it = this.watches.values().iterator(); > while (it.hasNext()) { > this.owner.fail(code, message, it.next(), true); > } > } >