Debuging added

This commit is contained in:
wengki81 2025-06-17 18:23:47 +08:00
parent 707e6e4221
commit a4ca0d1913
2 changed files with 30 additions and 1 deletions

View File

@ -78,7 +78,12 @@ class DumonGeolocation : Plugin() {
gpsManager = GpsStatusManager(
context,
onSatelliteStatusUpdate = { satelliteStatus = it },
onLocationUpdate = { location, isMocked ->
onLocationUpdate = onLocationUpdate@{ location, isMocked ->
if (location.latitude == 0.0 && location.longitude == 0.0) {
Log.w("GPS_LOCATION", "Ignored location update: (0.0, 0.0)")
return@onLocationUpdate
}
latestLatitude = location.latitude
latestLongitude = location.longitude
latestAccuracy = location.accuracy.toDouble()

View File

@ -80,6 +80,13 @@ class GpsStatusManager(
return
}
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Log.w("GPS_STATUS", "GPS Provider not enabled")
}
if (!locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
Log.w("GPS_STATUS", "Network Provider not enabled")
}
locationManager.registerGnssStatusCallback(gnssStatusCallback, null)
locationManager.requestLocationUpdates(
@ -97,6 +104,23 @@ class GpsStatusManager(
)
Log.d("GPS_STATUS", "GPS + Network location tracking started")
// 🔥 Fallback: coba ambil lokasi terakhir
val lastKnown = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
?: locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
lastKnown?.let { location ->
if (location.latitude != 0.0 && location.longitude != 0.0) {
val isMocked = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
location.isMock
} else {
location.isFromMockProvider
}
Log.d("GPS_STATUS", "Using last known location as fallback")
onLocationUpdate(location, isMocked)
}
}
} catch (e: SecurityException) {
Log.e("GPS_STATUS", "SecurityException", e)
}