I want to rotate marker as per bearing or sensor value received from Accelerometer to show the user where actually he is moving. I have set marker icon and flat value to tru
In Kotlin by using Google SphericalUtil class we can get bearing by passing source and destination LatLngs like:
fun calculateBearing(lat1: Double, lng1: Double, lat2: Double, lng2: Double): Float {
val sourceLatLng = LatLng(lat1, lng1)
val destinationLatLng = LatLng(lat2, lng2)
return SphericalUtil.computeHeading(sourceLatLng, destinationLatLng).toFloat()
}
Then set this result 'bearing` to the marker like
Val bearing = calculateBearing(lat1, lng1, lat2, lng2)
marker.rotation(bearing)
Reference: https://developers.google.com/maps/documentation/android-sdk/utility/#spherical