Permalink
Browse files

Merge pull request #14 from mschulkind/callback_master

Fix #197 and a related issue.
  • Loading branch information...
shazron committed Nov 22, 2011
2 parents d5962f1 + fd34247 commit 81bdce8b5e416a92262b3377b5cf5a407ba3d250
Showing with 27 additions and 1 deletion.
  1. +6 −0 PhoneGapLib/Classes/Location.m
  2. +21 −1 PhoneGapLib/javascripts/core/geolocation.js
@@ -177,6 +177,12 @@ - (void) startLocation:(NSMutableArray*)arguments withDict:(NSMutableDictionary*
}
// Tell the location manager to start notifying us of location updates
+ }
+
+ // Tell the location manager to start notifying us of location updates. We
+ // first stop, and then start the updating to ensure we get at least one
+ // update, even if our location did not change.
+ [self.locationManager stopUpdatingLocation];
[self.locationManager startUpdatingLocation];
__locationStarted = YES;
@@ -98,8 +98,24 @@ Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallba
params.timeout = options.timeout;
}
}
+
+ var successListener = win;
+ var failListener = fail;
+ if (!this.locationRunning)
+ {
+ successListener = function(position)
+ {
+ win(position);
+ self.stop();
+ };
+ errorListener = function(positionError)
+ {
+ fail(positionError);
+ self.stop();
+ };
+ }
- this.listener = {"success":win,"fail":fail};
+ this.listener = {"success":successListener,"fail":failListener};
this.start(params);
var onTimeout = function()
@@ -206,6 +222,8 @@ Geolocation.prototype.setLocation = function(position)
Geolocation.prototype.setError = function(error)
{
var _error = new PositionError(error.code, error.message);
+
+ this.locationRunning = false
if(this.timeoutTimerId)
{
@@ -226,12 +244,14 @@ Geolocation.prototype.setError = function(error)
Geolocation.prototype.start = function(positionOptions)
{
PhoneGap.exec(null, null, "com.phonegap.geolocation", "startLocation", [positionOptions]);
+ this.locationRunning = true
};
Geolocation.prototype.stop = function()
{
PhoneGap.exec(null, null, "com.phonegap.geolocation", "stopLocation", []);
+ this.locationRunning = false
};

0 comments on commit 81bdce8

Please sign in to comment.