Skip to content

derysudrajat/compass-qibla

Repository files navigation

ic_logo_compass_qibla

compass-qibla

Android Library to determine Qibla direction

Setup

Add this to build.gradle (project)

allprojects {
  repositories {
      ...
      maven { url 'https://jitpack.io' }
    }
}

Add this dependency to build.grdle (module) or if you using gradle 7+ put it to setting.gradle

dependencies {
  implementation 'com.github.derysudrajat:compass-qibla:1.0.0'
}

How to use

You can use this library just by add this code 🥳

CompassQibla.Builder(this)
    .onDirectionChangeListener { qiblaDirection -> 
        qiblaDirection.isFacingQibla // boolean variable indentify if you facing qibla
        qiblaDirection.compassAngle // float variable to rotate compass
        qiblaDirection.needleAngle // float variable to rotate compass needle

        // your awesome code here ...
    }.build()

The QiblaDirection is data class variable, this is detail about it

QiblaDirection
Variable Type Description
compassAngle Float a variable that can use to rotate your compass angle
needleAngle Float a variable that can use to rotate your compass needle angle
isFacingQibla Boolean a variable that identifies whether you are facing the Qibla or not

Also, you can configure the permission listener 😎

CompassQibla.Builder(this)
    .onPermissionGranted { permission ->
        // handle if location permission was granted
    }
    .onPermissionDenied { 
        // handle if location permission was denied
    }
    .onDirectionChangeListener { qiblaDirection -> 
        // your awesome code here ...
    }.build()

And last but not least if you wondering can I get the location address also? yes, you can! 👀

the Address variable is refer to android.location.Address by android

CompassQibla.Builder(this)
    .onGetLocationAddress { address ->
        // handle location address result
    }
    .onDirectionChangeListener { qiblaDirection -> 
        // your awesome code here ...
    }.build()

And this is the whole code that you can consume 🔥

CompassQibla.Builder(this)
    .onPermissionGranted { permission ->
        // handle if location permission was granted
    }
    .onPermissionDenied {
        // handle if location permission was denied
    }
    .onGetLocationAddress { address ->
        // handle location address result
    }
    .onDirectionChangeListener { qiblaDirection ->
        // your awesome code here ...
    }.build()

Sample App

Also you can check the sample app to get reference about this library

Keep chill and enjoyy 😎✨