Remove compass and track bearing
This commit is contained in:
@@ -37,6 +37,7 @@ import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider
|
||||
import org.osmdroid.views.overlay.mylocation.IMyLocationProvider
|
||||
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay
|
||||
import java.util.Locale
|
||||
import kotlin.math.abs
|
||||
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
@@ -44,6 +45,7 @@ class MainActivity : ComponentActivity() {
|
||||
private lateinit var map : MapView
|
||||
|
||||
private lateinit var currentLocation: Location
|
||||
private var lastBearing = 0.0f
|
||||
private lateinit var locationManager: LocationManager
|
||||
private lateinit var mapController: IMapController
|
||||
private lateinit var positionMarker: Marker
|
||||
@@ -69,19 +71,6 @@ class MainActivity : ComponentActivity() {
|
||||
Voice.LATENCY_LOW, true, null))
|
||||
tts.setSpeechRate(0.8f)
|
||||
|
||||
|
||||
val mySensorEventListener: SensorListener = object : SensorListener {
|
||||
override fun onSensorChanged(sensor: Int, values: FloatArray) {
|
||||
val mHeading = values[0]
|
||||
if(navigationEnable){
|
||||
map.mapOrientation = -mHeading
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAccuracyChanged(p0: Int, p1: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
locationManager = getSystemService(LOCATION_SERVICE) as LocationManager
|
||||
getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this))
|
||||
setContentView(R.layout.main)
|
||||
@@ -139,9 +128,9 @@ class MainActivity : ComponentActivity() {
|
||||
rotationGestureOverlay.isEnabled
|
||||
map.setMultiTouchControls(true)
|
||||
map.overlays.add(rotationGestureOverlay)
|
||||
val compassOverlay = CompassOverlay(this, InternalCompassOrientationProvider(this), map)
|
||||
compassOverlay.enableCompass()
|
||||
map.overlays.add(compassOverlay)
|
||||
// val compassOverlay = CompassOverlay(this, InternalCompassOrientationProvider(this), map)
|
||||
// compassOverlay.enableCompass()
|
||||
// map.overlays.add(compassOverlay)
|
||||
val locationOverlay =
|
||||
object : MyLocationNewOverlay(GpsMyLocationProvider(this), map) {
|
||||
override fun onLocationChanged(location: Location?, source: IMyLocationProvider?) {
|
||||
@@ -156,7 +145,13 @@ class MainActivity : ComponentActivity() {
|
||||
currentLocation = location
|
||||
latitude = location.latitude
|
||||
longitude = location.longitude
|
||||
if(navigationEnable && currentLocation.hasBearing()){
|
||||
lastBearing = currentLocation.bearing
|
||||
mapController.animateTo(GeoPoint(latitude, longitude), null, null, -currentLocation.bearing)
|
||||
}
|
||||
else{
|
||||
mapController.animateTo(GeoPoint(latitude, longitude))
|
||||
}
|
||||
|
||||
findViewById<TextView>(R.id.accuracy).text = "${location.accuracy} %"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user