Skip to content

Instantly share code, notes, and snippets.

@christocracy
Created May 20, 2015 04:31
Show Gist options
  • Save christocracy/bb2250128746d423c2ed to your computer and use it in GitHub Desktop.
Save christocracy/bb2250128746d423c2ed to your computer and use it in GitHub Desktop.
BackgroundGeolocation Geofence API
// Add custom longpress event for adding GeoFence with hard-coded radius 200m.
google.maps.event.addListener(app.map, 'longpress', function(e) {
if (app.geofence) {
app.geofence.setMap(null);
}
// Add the geofence with BackgroundGeolocation plugin
bgGeo.addGeofence({
identifier: 'MyGeofence',
radius: 200,
latitude: e.latLng.lat(),
longitude: e.latLng.lng()
}, function() {
// If iOS successfully created your geofence, success-callback runs.
// NOTE: iOS only allows 20 geofences ON ALL APPS COMBINED.
// ie: operating-system-wide limit of 20. Thus success callback here is important.
app.geofence = new google.maps.Circle({
fillColor: '#00cc00',
fillOpacity: 0.4,
strokeOpacity: 0,
radius: 200,
center: e.latLng,
map: app.map
});
});
});
// Finally, we set up a "geofence" listener. ALL geofence crossings execute
// this callback. Use the supplied identifier to map to a particular geofence
bgGeo.onGeofence(function(identifier) {
console.log('[js] Geofence ENTER: ', identifier);
switch (identifier) {
case 'HOME':
break;
case 'OFFICE':
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment