Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

In my device always comes lat and lon 0.0 #35

Open
AssisBernardo opened this issue Oct 11, 2017 · 3 comments
Open

In my device always comes lat and lon 0.0 #35

AssisBernardo opened this issue Oct 11, 2017 · 3 comments

Comments

@AssisBernardo
Copy link

AssisBernardo commented Oct 11, 2017

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() {

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)
    }
}

}
`

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?

@Zellius
Copy link
Owner

Zellius commented Oct 14, 2017

Hi :) Sorry for delay.

My colleague had the same issue on a single device with Android 8. And it has disappeared after one day.

It seems like Android LocationManager cannot receive location from any provider.

Can you please call requestSingleUpdate on UI thread. Do you receive any events in LocationListener?

@BDwuzhou
Copy link

@Zellius I have the same issue and I call requestSingleUpdate on UI thread like you said,but I did't receive any event,so wht's the problem?

@Zellius
Copy link
Owner

Zellius commented Dec 28, 2017

@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 free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants