In Streams 4.0, the geospatial toolkit introduced a new operator called Geofence.  The Geofence operator allows you to dynamically add or remove geographical regions of interest.  As entities move in and out of these regions, the operator will provide entry and exit events.

This video demonstrates how you can use the Geofence operator to run a smart marketing campaign.  The application monitors a number of cell phone users.  As users enter or exit a predefined geofence area, they will receive marketing information based on their current location.

You may find the source code of this demo in the Sample project on Github here:  Geofence Sample

11 comments on"Geofence – Smart Marketing"

  1. DanDebrunner April 25, 2015

    Great example, couple of questions.

    Does the GeoFence operator emit a tuple for every entity tuple it receives, or only if the latest entity location information causes some change in the entities fence membership? E.g. what happens if it receives continued location updates for an entity within a fence?

    When a new fence is created, will it calculate membership for existing entities in event mode?

    • Hi Dan,
      The Geofence operator emits a tuple for every incoming entity tuple. If it receives continued incoming tuples with location updates for an entity that is within a geofence A, an output tuple will be generated for each incoming tuple. If the operator is in event mode, then the FencesEntered and FencesExited functions will not include A. CurrentFences will always include A.
      When a new fence is created, it will not calculate membership for existing entities. This is because the Polygon stream is a control port, which does not generate output tuples.

  2. Muhammad Nabeel Shahid April 06, 2018

    I am having problems refereshing and connecting the StreamsDomain in streams studio. The error that I get while connecting the domain is :

    INFO:Refreshing domain StreamsDomain
    Refresh Domains failed: There were one or more problems refreshing the domains: There were one or more problems refreshing domain StreamsDomain: Streams domain StreamsDomain: Unable to connect to URL service:jmx:jmxmp://streamsqse.localdomain No route to host (Host unreachable)
    Connect to domain StreamsDomain failed: Streams domain StreamsDomain: Unable to connect to URL service:jmx:jmxmp://streamsqse.localdomain No route to host (Host unreachable)

    Any solutions??

  3. Hey!
    I’ve run the Geofence Marketing code, everything is working fine,the toolkits are updated too. But I can’t see the map on this URL http://PEHost:8080/map/map.html. Says this is taking too long to respond. How can I solve this problem?

  4. How can we exploit indoor positioning in this project?

    • Natasha DSilva May 24, 2018

      Hi,
      Can you please clarify what you mean by indoor positioning? Are you trying to track objects or people moving about indoors?

      • Hello,
        I have number of questions.
        1. How does geofence and IBM streams connected to mobile phone.because when I move my cell phone i expect the real time gps coordinates will go inside geofence and then fence is created on my run time location.
        2. If I want to achieve same geofencing in indoor environment again through mobile how can i do this? for eg i am standing outside floor 1 room 2 how will i get ads targeted for this location. I have been seeing some techniques like fingerprint but it requires RSSI, MAC address information. How can IBM Streams acquire it? If It acquire it i can apply machine learning on this.
        3. I can do above task easily using android app. Then how does we differentiate android app and ibm streams? what is there in IBM streams that we cant do through android app?
        4. Link is missing b/w android app and ibm streams
        Honestly i thought of IBM stream as a powerful real time tool but i am disappointed as i found its no such integration/ linking with the most important real time data generator that is “mobile phone”.

        Please answer

        • Martin Siegenthaler May 29, 2018

          Hi:
          The demo is using a file of locations, as I read your question you’d like to know what it takes to get live data from an Android phone into Streams. You’ll need a few pieces.

          You need to get the gps location which involves writing a Andorid application to get the location and send the data to Streams.

          To get the high definition location you’ll want to use the NETWORK_PROVIDER with a ACCESS_FINE_LOCATION which are features of the android.location API. I found this description of ‘location strategies’ here, https://developer.android.com/guide/topics/location/strategies
          Many things to take into account, security, cost, battery life etc.

          You’ll want an android development environment since it will take care of all the configuration issues for your specific phone.

          Once you get the location you’ll need to get it to Streams. This can get into security issues if you want to do it via a web connection since your going from the internet where the phone is to an internal network be it in QSE or the Cloud. I’d avoid the web connection and go with MessageHub. The Kafka publish api can send messages to MessageHub and Streams can pick them up using the MessageHub tookit.

          The big issue with creating an application is taking care of all the various version of libraries, phone models models and security with it’s various opt in/out aspects. Using the development environment for a specific model/hardware is simpler than taking care of all the variations that exist in the wild (ugly).
          I’ve don’t have an Android environment, all my experience is in the IPhone arena. Hopefully this will give you a direction.

        • Natasha DSilva May 29, 2018

          Hi @hahmed05,
          I think Martin’s answer above will help address your comments about connecting your phone and Streams.
          Basically, you need a way to send the location from your phone to Streams, and then Streams can process the location.
          You need an Android app that will send the data to Streams, whether through Kafka, or MQTT, RabbitMQ, or any other messaging that is supported by Streams.
          Various Streams toolkits exist that will connect to these systems. These are called adapter toolkits and you can see the full list of such toolkits on this link, under Adapters.

          To your next question, indoor geofencing based on RSSI or other radio fingerprinting mechanisms is not covered by the Geofence operator. It would require training a model that identifies a presence zone based on RSSI measurements from multiple vantage points (e.g., multiple Bluetooth or WiFi access points). To begin with such a model can simply represent each each presence zone as a set of access points visible from that zone (e.g., zone id 1: ). This may create some collisions, i.e, two presence zones may “see” the same set of access points. It is only those cases that RSSI can be used to further differentiate between the two zones. Having said that RSSI measurements are device specific, OS version specific and is impacted by changes indoor settings (e.g., new rack of books in a library).

          Finally, regarding the difference between doing geofencing on your phone and in Streams, there are several and it depends on what you are trying to do.
          In this case, the most relevant difference is that Streams will serve as a fast central analytics system. For a company with millions of customers moving in and out of different geofences, how will you process the location of millions of users on a phone? You might also need to be able to check a database of customer information, which again is not available on your phone.
          However, if all the customers have your Android app that is sending their location to Streams, Streams can process that data incredibly quickly. After processing each customer’s data, Streams can connect to another database to look up their information and send them a discount, alerts, e.t.c. as shown in the video above.
          For example in some tests using Streams to process data from Kafka they reached a rate of 1 million messages per second.

          Hope this helps answer your questions.

Join The Discussion