This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) { | |
if (provider == LocationManager.GPS_PROVIDER) { | |
if (status == LocationProvider.OUT_OF_SERVICE) { | |
notifyLocationProviderStatusUpdated(false) | |
} else { | |
notifyLocationProviderStatusUpdated(true) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val batteryInfoReceiver = object : BroadcastReceiver() { | |
override fun onReceive(ctxt: Context, intent: Intent) { | |
val batteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0) | |
val scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1) | |
val batteryLevelScaled = batteryLevel / scale.toFloat() | |
batteryLevelArray.add(Integer.valueOf(batteryLevel)) | |
batteryLevelScaledArray.add(java.lang.Float.valueOf(batteryLevelScaled)) | |
batteryScale = scale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Kalman Filter */ | |
var Qvalue: Float = 3.0f | |
val locationTimeInMillis = location.elapsedRealtimeNanos / 1000000 | |
val elapsedTimeInMillis = locationTimeInMillis - runStartTimeInMillis | |
if (currentSpeed == 0.0f) { | |
Qvalue = 3.0f //3 meters per second | |
} else { | |
Qvalue = currentSpeed // meters per second |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressLint("NewApi") | |
private fun getLocationAge(newLocation: Location): Long { | |
val locationAge: Long | |
if (android.os.Build.VERSION.SDK_INT >= 17) { | |
val currentTimeInMilli = SystemClock.elapsedRealtimeNanos() / 1000000 | |
val locationTimeInMilli = newLocation.elapsedRealtimeNanos / 1000000 | |
locationAge = currentTimeInMilli - locationTimeInMilli | |
} else { | |
locationAge = System.currentTimeMillis() - newLocation.time | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun filterAndAddLocation(location: Location): Boolean { | |
val age = getLocationAge(location) | |
if (age > 5 * 1000) { //more than 5 seconds | |
Log.d(LOG_TAG, "Location is old") | |
oldLocationList.add(location) | |
return false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onLocationChanged(newLocation: Location?) { | |
newLocation?.let{ | |
Log.d(LOG_TAG, "(" + it.latitude + "," + it.longitude + ")") | |
gpsCount++ | |
if (isLogging) { | |
//locationList.add(newLocation); | |
filterAndAddLocation(it) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun zoomMapTo(location: Location) { | |
val latLng = LatLng(location.latitude, location.longitude) | |
try { | |
map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17.5f)) | |
this.didInitialZoom = true | |
return | |
} catch (e: Exception) { | |
e.printStackTrace() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun zoomMapTo(location: Location) { | |
val latLng = LatLng(location.latitude, location.longitude) | |
if (this.didInitialZoom == false) { | |
try { | |
map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17.5f)) | |
this.didInitialZoom = true | |
return | |
} catch (e: Exception) { | |
e.printStackTrace() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun addPolyline() { | |
locationService?.locationList?.let{locationList -> | |
runningPathPolyline?.let{ | |
val toLocation = locationList[locationList.size - 1] | |
val to = LatLng( | |
toLocation.latitude, | |
toLocation.longitude | |
) | |
val points = it.points |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun drawUserPositionMarker(location: Location) { | |
val latLng = LatLng(location.latitude, location.longitude) | |
if (this.userPositionMarkerBitmapDescriptor == null) { | |
userPositionMarkerBitmapDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.user_position_point) | |
} | |
userPositionMarker?.let{ | |
it.setPosition(latLng) | |
} ?: run{ |
NewerOlder