The Android application shows the location of the containment zones to the users. It also notifies the user when he or she trespasses the boundary of a containment zone or stays in the containment zones (Fig.1). All these functionalities are achieved by the help of Firebase and Geofencing tools from Google.
Fig.1 Methodology of the app
Firebase Cloud Firestore
A real-time database is created in Google Cloud Firestore which contains all the data related to the containment zones like latitudes, longitude, radius and zone names. Cloud Firestore features a NoSQL, document-oriented database (Firebase Cloud Firestore). There are no tables or rows. Instead, the location data are stored in documents, which are organized into collections. All the containment zones are stored in a collection in which each containment zone is represented as an individual document. Each document has four fields namely “Lat”, “Long”, “locationName” and “radius” for storing latitudes, longitudes, location names and radius, respectively. Fig.2 shows the document-oriented Cloud Firestore database with data of few containment zones. The “radius” field in each document is used to indicate the radius of the containment zone. The names of the fields must match the JAVA objects created in the Android application in order to properly extract each data from the database correctly. The Cloud firestore is connected to the android application by registering the SHA-1 (Secure Hash Algorithm 1) certificate fingerprint of the application in the Firebase project settings. After the database is connected, the location data of the containment zones can be retrieved by the Android application and can be shown in Google map.
Fig.2 Cloud Firestore database with location data of containment zones
Geofencing
As the location data is received by the Android application, geofences are created using the latitude, longitude and radius of the containment zones. Every geofence requires the latitude and longitudes of the geofencing area and a radius to determine the boundary of the geofence. Along with these, a unique id or key is also required to be set to each geofences. This unique key is generated from the names of the containment zones. The locations of the containment zones along with the user’s current location are shown using Google maps in the application. The containment zones are shown using markers and circles. The markers are set using the latitude and longitude of the containment zones and the circles are set around the markers using the radius provided. Fig.3 shows a screenshot of the app showing the containment zones in Kolkata. The current location of the user is shown in the map and the changes in the user’s location get updated in the map instantly. Whenever a user enters a containment zone, the geofence broadcast receiver gets triggered and notifies the user. A notification is given to the user according to the triggering event that is entering and exiting the containment zones.
The app further extracts the IMEI number of the trespasser and uploads it to the online database. This IMEI number can be useful to the local police to track and identify people who are frequently trespassing the containment zones. The app is programmed to work in background and the geofences get triggered even if the app is not open in foreground.
Fig.3 Containment zones in Kolkata