Follow Us

Realtime geofencing

GPS & Uber-like apps made easy

Kuzzle Backend’s geospatial engine provides a powerful geofencing feature which lets you define boundaries, distance, distance range, & polygons.
Geofencing can be used to trigger push notifications based on location detection or build geographical data streams such as those used for GPS tracking.
Read the documentation to learn more

Case Study

IOT GEOLOCATION MONITORING

Kuzzle Backend enables live tracking of a set of connected bikes and sends notifications when the bikes enter or exit a specified area.

Blazing fast realtime geofencing engine

Developers Corner

Reduce your development time with Kuzzle's SDKs, these provide high-level APIs to the Kuzzle Backend to help you get started quickly.
To learn more read our guide

  • Javascript
  • Android
  • GO
  • // Subscribe to document leaving a geodistance perimeter
    
    var filter = {
      geoDistance: {
        location: {
          lat: 51.5029017,
          lon: -0.1606903
        },
        distance: '10km'
      }
    }
    
    kuzzle
        .collection('mycollection', 'myindex')
        .subscribe(filter, {scope: 'out'}, function(error, result) {
        // triggered each time a document leaving the geodistance filter !
        console.log('Document is leaving the perimeter:', result)
    })
    
    // Update a document (that will notify client that subscribed with the code above)
    
    /*
    Existing document within the geodistance perimeter, stored into Kuzzle:
    {
      _id: '326c8f08-63b0-429f-8917-b782d30930e9',
      firstName: 'Ada',
      lastName: 'Lovelace',
      location: {
        lat: 51.519291,
        lon: -0.149817
      }
    }
    */
    
    var newLocation = {
      lat: 32.692742,
      lon: -97.114127
    }
    
    kuzzle
      .collection('mycollection', 'myindex')
      .updateDocument('326c8f08-63b0-429f-8917-b782d30930e9', {location: newLocation})
        
  • 
    // Subscribe to document leaving a geodistance perimeter
    
    JSONObject filter = new JSONObject()
      .put("geoDistance", new JSONObject
        .put("location", new JSONObject
            .put("lat": 51.5029017)
            .put("lon": -0.1606903))
        .put("distance", "10km"));
    
    kuzzle.collection("mycollection", "myindex")
      .subscribe(filter, new RoomOptions().setScope("out"), new ResponseListener<NotificationResponse>() {
        @Override
        public void onSuccess(NotificationResponse object) {
          // triggered each time a document leaving the geodistance filter
          System.out.println("Document is leaving the perimeter:" + object.getResult().toString());
        }
      });
              
    // Update a document
    
    JSONObject newLocation = new JSONObject()
      .put("lat": 32.692742)
      .put("lon": -0.1606903);
    
    kuzzle.collection("mycollection", "myindex")
      .updateDocument("326c8f08-63b0-429f-8917-b782d30930e9", newLocation);
                  
  • 
    ro := types.NewRoomOptions()
    cn := websocket.NewWebSocket(":7512", o)
    k, _ := kuzzle.NewKuzzle(cn, o)
    c := collection.NewCollection(k, "mycollection", "myindex")
    
    // Subscribe to document leaving a geodistance perimeter
    type Location struct {
      Lat float64 `json:"lat"`
      Lon float64 `json:"lon"`
    }
    type GeoDistance struct {
      Location Location `json:"location"`
      Distance string `json:"distance"`
    }
    type GeofencingFilters struct {
      GeoDistance GeoDistance `json:"geoDistance"`
    }
    
    var filters = GeofencingFilters{
      GeoDistance: GeoDistance{
        Location: Location{
      	  Lat: 51.5029017,
      	  Lon: -0.1606903,
    	},
    	Distance: "10km",
      },
    }
    rtc := make(chan types.KuzzleNotification)
    res := <- c.Subscribe(filters, ro.SetScope("out"), rtc)
    
    go func (rtc chan types.KuzzleNotification) {
      fmt.Println("Document is leaving the perimeter: ")
      fmt.Println(<-rtc)
    }(rtc)
    
    
    // Update a document (that will notify client that subscribed with the code above)
    
    var newLocation = Location{
      Lat: 32.692742,
      Lon: -97.114127,
    }
    
    res, err := c.updateDocument("326c8f08-63b0-429f-8917-b782d30930e9", newLocation, nil)
    

They Trust us