Permalink
Browse files

working on fence

  • Loading branch information...
1 parent d944cea commit 36434e4b2b1e22d8dbfbb3e80a233da1164e3b15 @bmoren committed Nov 8, 2015
Showing with 20 additions and 19 deletions.
  1. +19 −17 p5.geolocation.js
  2. BIN p5geolocation.png
  3. +1 −2 readme.md
View
@@ -191,35 +191,37 @@ p5.prototype.calcGeoDistance = function(lat1, lon1, lat2, lon2, units) {
return d;
}
-p5.prototype.geoFence = function(lat, lon, fence, callback, units, options){
+p5.prototype.geoFence = function(lat, lon, fence, insideCallback, outsideCallback, units, options){
this.lat = lat;
this.lon = lon;
this.fence = fence;
this.units = units; //this should work since calcGeoDistance defaults to miles.
- this.watch;
this.distance;
+ this.insideCallback = insideCallback
+ this.outsideCallback = outsideCallback
+ if (navigator.geolocation) {
+ navigator.geolocation.watchPosition(success, geoError, options);
+ }else{
+ geoError("geolocation not available");
+ };
- if (navigator.geolocation) {
- this.watch = navigator.geolocation.watchPosition(success, geoError, options);
- }else{
- geoError("geolocation not available");
- };
-
- function geoError(message){
- console.log(message);
- }
+ function geoError(message){
+ console.log(message);
+ }
- function success(position){
+ function success(position){
- this.distance = calcGeoDistance(this.lat,this.lon, position.coords.latitude, position.coords.longitude, this.units);
+ this.distance = calcGeoDistance(this.lat,this.lon, position.coords.latitude, position.coords.longitude, this.units);
- if(this.distance < this.fence){
- //were inside the fence
- if(typeof callback == 'function'){ callback(position.coords) };
+ if(this.distance < this.fence){
+ //were inside the fence
+ if(typeof callback == 'function'){ this.insideCallback(position.coords) };
+ }else{
+ if(typeof callback == 'function'){ this.outsideCallback(position.coords) };
+ }
}
- }
}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1,7 +1,6 @@
###p5.geolocation
-Common Geolocation techniques & tools for p5.js
-
+p5.geolocation provides techniques for getting, watching, calculating, and geo fencing users locations.
Parts of this activity are made possible by a research grant from Forecast Public Art and the Jerome Foundation

0 comments on commit 36434e4

Please sign in to comment.