Skip to content

Instantly share code, notes, and snippets.

Created May 20, 2015 04:31
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
BackgroundGeolocation Geofence API
// Add custom longpress event for adding GeoFence with hard-coded radius 200m.
google.maps.event.addListener(, 'longpress', function(e) {
if (app.geofence) {
// Add the geofence with BackgroundGeolocation plugin
identifier: 'MyGeofence',
radius: 200,
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,
// 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':
case 'OFFICE':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment