Skip to content

GFG-CLUB-KIIT/baysafe

Repository files navigation

Baysafe

Features

  1. Detects unsafe locations in the user's route either via Push Notifications or shown in map.
  2. Select and mark an area it as unsafe.
  3. S.O.S. button on clicking which the user’s location would be shared with users.

Tech Stack

  • Native Android Kotlin
  • UI/UX - Figma OR Adobe XD
  • Google Places SDK
  • Navigation
  • View Mode
  • Live Data
  • Data Store Preferences
  • Data Binding
  • Coroutines
  • Retrofit

Working

  • The core of the app is the Google-Places SDK. A user can create a geofence, with a selected radius(in the range of 1km-10km) to mark it as unsafe. Once marked unsafe, a red region forms around the geofence.
  • The corresponding Latitude and Longitude and radius gets stored in an object of class GeofenceDetails, as well as gets uploaded to the Firebase Realtime-Database.

Activating the Geofence

The data is actually the longitude and latitude of the region, and radius of the Geofence. This is how the geofence is activated:
val geofence = Geofence.Builder()
                .setRequestId(position.toString())
                .setCircularRegion(
                    location.latitude,
                    location.longitude,
                    radius
                )
                .setExpirationDuration(Geofence.NEVER_EXPIRE)
                .setTransitionTypes(
                    Geofence.GEOFENCE_TRANSITION_ENTER or Geofence.GEOFENCE_TRANSITION_EXIT or Geofence.GEOFENCE_TRANSITION_DWELL
                )

Uploading the data

The following snippet of code is used to add the selected region to firebase
fun addGeofence(location: LatLng, radius: Double) {
        //Upload on Firebase
        DataDetails.geofencesList.clear()
        val model= GeofenceDetails2(location.latitude,location.longitude,radius.toDouble())
        val uniqueID = mDatabaseRef.push().key

        if (uniqueID != null) {
            mDatabaseRef.child(uniqueID).setValue(model).addOnSuccessListener {
                Log.d("SharedViewModel", "Geofence successfully added")
            }
        }
    }