Skip to content

Commit

Permalink
Merge pull request #7 from lmccart/master
Browse files Browse the repository at this point in the history
adding clear for geofences
  • Loading branch information
bmoren committed Aug 19, 2016
2 parents fcab98f + 7e1d9e2 commit 1c4c338
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions p5.geolocation.js
Expand Up @@ -246,6 +246,7 @@ p5.prototype.geoFenceCircle = function(lat, lon, fence, insideCallback, outsideC
this.outsideCallback = outsideCallback;
this.insideFence = false;
this.options = options;
this.id = '';

this.geoError = function(message){
console.log("geoFenceCircle Error :" + message);
Expand All @@ -262,10 +263,17 @@ p5.prototype.geoFenceCircle = function(lat, lon, fence, insideCallback, outsideC
this.insideFence = false;
}
}

this.clear = function() {
if (this.id) {
navigator.geolocation.clearWatch(this.id);
this.id = '';
}
}

if (navigator.geolocation) {
// bind the callbacks to the geoFenceCircle 'this' so we can access, this.lat, this.lon, etc..
navigator.geolocation.watchPosition(this.success.bind(this), this.geoError.bind(this), this.options);
this.id = navigator.geolocation.watchPosition(this.success.bind(this), this.geoError.bind(this), this.options);
}else{
geoError("geolocation not available");
};
Expand Down Expand Up @@ -305,6 +313,7 @@ p5.prototype.geoFencePolygon = function( ArrayOfObjectsWithLatLong, insideCallba
this.outsideCallback = outsideCallback;
this.insideFence = false;
this.options = options;
this.id = '';

this.geoError = function(message){
console.log("geoFencePolygon Error :" + message);
Expand All @@ -319,10 +328,17 @@ p5.prototype.geoFencePolygon = function( ArrayOfObjectsWithLatLong, insideCallba
if(typeof this.outsideCallback == 'function'){ this.outsideCallback(position.coords) };
}
}

this.clear = function() {
if (this.id) {
navigator.geolocation.clearWatch(this.id);
this.id = '';
}
}

if (navigator.geolocation) {
// bind the callbacks to the geoFenceCircle 'this' so we can access, this.lat, this.lon, etc..
navigator.geolocation.watchPosition(this.success.bind(this), this.geoError.bind(this), this.options);
this.id = navigator.geolocation.watchPosition(this.success.bind(this), this.geoError.bind(this), this.options);
}else{
geoError("geolocation not available");
};
Expand Down

0 comments on commit 1c4c338

Please sign in to comment.