No code geofencing solution in five minutes with Mapify

Mapify can help you setup your geofencing solution quickly and without requiring any code.


TL;DR;

In this post you will go through the process of creating a simple geofencing process to include in your own solution, without requiring you to write any code. You'll build a quick and simple solution to have email alerts sent to you whenever a vehicle moves into one of several restricted zones.


Requirements:

  • Mapify account (you can request a trial account here)


If you want to dive right in the deep end without following this tutorial, feel free to request a Mapify trial here, or click here to schedule a talk with us, and start creating your location intelligence solutions today!


Why would you need geo fencing in your business


Simply put, "a geofence is a virtual perimeter for a real-world geographic area". Many businesses use geofences to provide value added services to their users. You can see geofencing in action in asset tracking applications which send alerts when an asset is inside or outside a specific restricted area but there are many other possible applications.


Building a simple geofencing solution with Mapify


In this article you will be using Mapify to create a simple geofencing solution for sending your email alerts when a fictional vehicle enters one of three restricted zones that you'll also define. And you will be able to have it up and running in 3 quick and easy steps:


  • Step 1 -  Create a "Restricted Zones" Dataset and Layer where you will define the restricted zones as polygons.

  • Step 2 - Create an "inbound-vehicle-positions" Data Feed to handle the incoming vehicle locations messages.

  • Step 3 - Create a "Process Vehicle Positions" Workflow which will process the vehicle messages and determine if each vehicle position received is inside one of the restricted zones and, if so, sends an email alert.

  • Optional - Create a Map to display the restricted zones and the transgressions in real time.

Step 1 - Create a "Restricted Zones" Dataset and Layer


The first step is to create a Dataset to hold the restricted zones polygons.


Create a new Dataset, name it "Restricted Zones", select "Polygon" as its geom type, and add the following fields:

  • id (numeric)

  • name (text)

  • type (numeric)


Once the "Restricted Zones" Dataset is created, you can add polygons to it, which will define the restricted zones. In the Dataset's details screen, click on the "Edit data on Editor" button to access Mapify Editor.


In Mapify Editor zoom in to Lisbon (Portugal) until you have a pretty good view of the city area, and click on the "Create Feature" button to add a new restricted zone. Select "Polygon" from the polygon creation toolbar, and draw a polygon which represent one of your restricted zones.


For its attribute values, use:


id = 1 name = Zone 1 type = 1


Save your new polygon. You can see an example of what it could look like in the screenshot below:

Add two more restricted zones, using the following values for its attributes:


id = 2

name = Zone 2

type = 2


and


id = 3

name = Zone 3

type = 1


After you're done adding your restricted zones, be sure to publish your changes to the Dataset, by clicking the "Publish Dataset" button in the Mapify Editor.


Depending on how you drew your restricted zones polygons, you will end up with something similar to the screenshot below:


Now all you need to do is create a new "Restricted Zones" GeoJSON Layer based on the "Restricted Zones" Dataset:



Don't forget to publish your layer once you create it, and you should end up with a layer that renders your restricted zones:



Step 2 - Create an "inbound-vehicle-positions" Data Feed


For the purpose of this article, your Data Feed will be able to handle incoming messages such as the fictional example below:


{
 "vehicle_id": "Vehicle01",
 "vehicle_type": "Car",
 "location": {
     "type": "MultiPoint",
     "coordinates": [ 
            [-9.183098,38.766037] 
     ]
   }
}
   

Create a new Data Feed name it "inbound-vehicle-positions", select "Push" as its type, and copy the following schema to its message JSON schema input box:


{
  "type": "object",
  "required": [],
  "properties": {
    "vehicle_id": {
      "type": "string"
    },
    "vehicle_type": {
      "type": "string"
    },
    "location": {
      "type": "object",
      "required": [],
      "properties": {
        "type": {
          "type": "string"
        },
        "coordinates": {
          "type": "array"
        }
      }
    }
  }
}

You should end up with a Data Feed configured as shown in the screenshot below:



Step 3 - Create a "Process Vehicle Positions" Workflow


Create a new Workflow and name it "Process Vehicle Positions". Add three different nodes to it, linking each node to the previous one created:


Source Node


The Source node defines which Data Feed this Workflow will subscribe to and handle its incoming messages.


Select the previously created "inbound-vehicle-positions" Data Feed as the source for this workflow.



Filter Node - Spatial Intersection - Mapify Layer


The Filter node filters out incoming messages, by only letting through to the next node messages which match its condition (in this case, those whose location data intersects any feature of the selected Layer).


Name: "Intersect Restricted Zones"

Layer: "Restricted Zones"

GeometryType: "MultiPoint"

Coordinates: "location.coordinates"



Sink Node - Email


The Sink node is an output node, which in this case will trigger an email being sent for each message it receives from the parent node.


Name: "Send Alert Email"

Subject: "ALERT: Vehicle ${vehicle_id} is in a Restricted Zone"

To email address: (your email address)

Body: "ALERT: Vehicle ${vehicle_id} is in a Restricted Zone"



After you have setup your workflow nodes, you should end up with a workflow looking like the screenshot below:



Run it !


In order to test and demonstrate your geofencing process working, we'll use Mapify Simulator to generate simulated vehicle positions and send them to the previously created Data Feed. 


In our example above, inbound vehicle messages include vehicle_id, vehicle_type and location attributes. So we'll configure the simulator to generate some vehicle's data and send it to the "inbound-vehicle-positions" Data Feed.


In order for Mapify Simulator to access the Data Feed and publish messages to it, you will need to create an API Key with the following claims:


Data Feeds - read

Topic Messaging - write



Open Mapify Simulator in a new tab in your browser and copy the API Key you just created to the respective field. You will be able to select the "inbound-vehicle-positions" Data Feed, and it should automatically display its message schema in the Template input box.



In this article you will only simulate a single vehicle moving at this time so, in the message template, replace the "string" value in the vehicle_id field with "Vehicle01", and for the vehicle_type field value replace it with "Car".


</