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.IMyLocationProvider
|
||||||
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay
|
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
@@ -44,6 +45,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
private lateinit var map : MapView
|
private lateinit var map : MapView
|
||||||
|
|
||||||
private lateinit var currentLocation: Location
|
private lateinit var currentLocation: Location
|
||||||
|
private var lastBearing = 0.0f
|
||||||
private lateinit var locationManager: LocationManager
|
private lateinit var locationManager: LocationManager
|
||||||
private lateinit var mapController: IMapController
|
private lateinit var mapController: IMapController
|
||||||
private lateinit var positionMarker: Marker
|
private lateinit var positionMarker: Marker
|
||||||
@@ -69,19 +71,6 @@ class MainActivity : ComponentActivity() {
|
|||||||
Voice.LATENCY_LOW, true, null))
|
Voice.LATENCY_LOW, true, null))
|
||||||
tts.setSpeechRate(0.8f)
|
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
|
locationManager = getSystemService(LOCATION_SERVICE) as LocationManager
|
||||||
getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this))
|
getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this))
|
||||||
setContentView(R.layout.main)
|
setContentView(R.layout.main)
|
||||||
@@ -139,9 +128,9 @@ class MainActivity : ComponentActivity() {
|
|||||||
rotationGestureOverlay.isEnabled
|
rotationGestureOverlay.isEnabled
|
||||||
map.setMultiTouchControls(true)
|
map.setMultiTouchControls(true)
|
||||||
map.overlays.add(rotationGestureOverlay)
|
map.overlays.add(rotationGestureOverlay)
|
||||||
val compassOverlay = CompassOverlay(this, InternalCompassOrientationProvider(this), map)
|
// val compassOverlay = CompassOverlay(this, InternalCompassOrientationProvider(this), map)
|
||||||
compassOverlay.enableCompass()
|
// compassOverlay.enableCompass()
|
||||||
map.overlays.add(compassOverlay)
|
// map.overlays.add(compassOverlay)
|
||||||
val locationOverlay =
|
val locationOverlay =
|
||||||
object : MyLocationNewOverlay(GpsMyLocationProvider(this), map) {
|
object : MyLocationNewOverlay(GpsMyLocationProvider(this), map) {
|
||||||
override fun onLocationChanged(location: Location?, source: IMyLocationProvider?) {
|
override fun onLocationChanged(location: Location?, source: IMyLocationProvider?) {
|
||||||
@@ -156,7 +145,13 @@ class MainActivity : ComponentActivity() {
|
|||||||
currentLocation = location
|
currentLocation = location
|
||||||
latitude = location.latitude
|
latitude = location.latitude
|
||||||
longitude = location.longitude
|
longitude = location.longitude
|
||||||
mapController.animateTo(GeoPoint(latitude, 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} %"
|
findViewById<TextView>(R.id.accuracy).text = "${location.accuracy} %"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user