You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.
i had created an app for control of bike tours, during the tour will be saved the coordinates of a cyclist on local database and i used RxLocationManager for catch lat and lon, but in my device lat and lon always comes 0.0.
i use GcmNetworkManager for execute in background to
dribble the doze mode and kotlin, but i think that not have incompatibilities
this is my service:
`
class CoordinatorService : GcmTaskService() {
private var location: Location? = null
override fun onRunTask(p0: TaskParams?): Int {
retrieveCoordinate();
lockThreadUntilLocationNotNull()
if(location == null || location?.latitude == 0.0){
Log.i("log_cat", "ERRO")
return GcmNetworkManager.RESULT_RESCHEDULE
}else{
Log.i("log_cat", "SUCESSO")
return GcmNetworkManager.RESULT_SUCCESS
}
}
private fun retrieveCoordinate() {
val locationRequestBuilder = LocationRequestBuilder(applicationContext)
locationRequestBuilder.addLastLocation(LocationManager.NETWORK_PROVIDER, LocationTime(20, TimeUnit.SECONDS), IgnoreErrorTransformer(null))
.addRequestLocation(LocationManager.GPS_PROVIDER, LocationTime(60, TimeUnit.SECONDS))
.setDefaultLocation(Location(LocationManager.PASSIVE_PROVIDER))
.create()
.subscribe(object : Subscriber<Location>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {}
override fun onNext(l: Location) {
location = l
Log.i("log_cat", l.latitude.toString() +" "+ l.longitude.toString())
}
})
}
private fun lockThreadUntilLocationNotNull() {
while (location == null) {
SystemClock.sleep(1000)
}
}
@BDwuzhou Did you tried to use the LocationManager.NETWORK_PROVIDER? Do you have same issue?
Android LocationManager will not call any LocationListener's method if the device cannot receive a Location from the provider. Usually network provider works better than gps. Especially inside buildings. But it may not work too.
Does my example work on your device? Did you tried to run your code on the emulator and send fake locations? You can try to send fake location on your device too via apps.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
good morning, can help me
i had created an app for control of bike tours, during the tour will be saved the coordinates of a cyclist on local database and i used RxLocationManager for catch lat and lon, but in my device lat and lon always comes 0.0.
i use GcmNetworkManager for execute in background to
dribble the doze mode and kotlin, but i think that not have incompatibilities
this is my service:
`
class CoordinatorService : GcmTaskService() {
}
`
manifest already has:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
on logcat two lines:
0.0 0.0
ERRO
the most intresting is that in other device the same code generate lat e lon correctly, my device is android 5 and other device is android 6,
all permissions have granted and gps e wifi connected, i check this before start the service on Activity
what wrong in my device/app?
The text was updated successfully, but these errors were encountered: