Mr. Ash
Mr. Ash

Reputation: 1

How to add my destination bearing angle with respect to compass in kotlin

I have made an application with bearing angle of destination location from my current location and compass which gives north direction.

private fun calculateBearing(
    currentLatitude: Double,
    currentLongitude: Double,
    targetLatitude: Double,
    targetLongitude: Double,
): Float {
    val currentLocation = Location("")
    currentLocation.latitude = currentLatitude
    currentLocation.longitude = currentLongitude

    val targetLocation = Location("")
    targetLocation.latitude = targetLatitude
    targetLocation.longitude = targetLongitude

    return currentLocation.bearingTo(targetLocation)
}

override fun onSensorChanged(event: SensorEvent?) {
    val degree = Math.round(event!!.values[0])
    currentDegree = (-degree).toFloat()
    heading.text = "Heading: $degree degrees"

    val ra = RotateAnimation(
        currentDegree, (-degree).toFloat(), Animation.RELATIVE_TO_SELF, 0.5f,
        Animation.RELATIVE_TO_SELF, 0.5f
    )
    ra.duration = 210
    ra.fillAfter = true
    imageView.startAnimation(ra)
}

What I actually require is the destination bearing angle should move with respect to my compass direction. So that, I can move to destination direction with my phones direction. I appreciate if anyone help me with this query in Kotlin.

Upvotes: 0

Views: 73

Answers (0)

Related Questions