yayaa / LocationManager

Simplify getting user's location for Android
807 stars 187 forks source link

No live tracking #99

Closed officialtanuj closed 4 years ago

officialtanuj commented 4 years ago

i used the following condition but i dont get periodic updates ,only single time

Configuration

public static LocationConfiguration silentConfiguration(boolean keepTracking) { final int WAIT_PERIOD = 1000;

    LocationRequest locationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setFastestInterval(WAIT_PERIOD).setSmallestDisplacement(1);

    //google play services configuration
    GooglePlayServicesConfiguration gpsc = new GooglePlayServicesConfiguration.Builder()
            .locationRequest(locationRequest)
            .askForGooglePlayServices(true)
            .askForSettingsApi(true)
            .ignoreLastKnowLocation(true)
            .setWaitPeriod(2000)
            .build();

    return new LocationConfiguration.Builder()
            .keepTracking(keepTracking)
            .useGooglePlayServices(gpsc)
            .useDefaultProviders(new DefaultProviderConfiguration.Builder()
                    .requiredDistanceInterval(0)
                    .acceptableAccuracy(1.0f)
                    .requiredTimeInterval(WAIT_PERIOD)
                    .acceptableTimePeriod(WAIT_PERIOD)
                    .setWaitPeriod(ProviderType.GPS,  WAIT_PERIOD)
                    .setWaitPeriod(ProviderType.NETWORK,  WAIT_PERIOD).build())
            .build();
}
yayaa commented 4 years ago

Are you using "keepTracking" true? Can you follow on the logs which provider is being used? And maybe share the logs as well, so I can tell more about what's going on :)

officialtanuj commented 4 years ago

yes i was using the keep tracking i used different time wait period for GooglePlayServicesConfiguration and it works fine generally it takes few sec initially for GooglePlayServicesConfiguration to work compared to DefaultProviderConfiguration

here is my final method i used it works

    public static LocationConfiguration defaultConfiguration() {
    LocationRequest locationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(4000).setFastestInterval(1000).setSmallestDisplacement(1);

    //google play services configuration
    GooglePlayServicesConfiguration gpsc = new GooglePlayServicesConfiguration.Builder()
            .locationRequest(locationRequest)
            .fallbackToDefault(true)
            .askForGooglePlayServices(true)
            .askForSettingsApi(true)
            .ignoreLastKnowLocation(true)
            .setWaitPeriod(4000)
            .build();

    return new LocationConfiguration.Builder()
            .keepTracking(true)
            .useGooglePlayServices(gpsc)
            .useDefaultProviders(new DefaultProviderConfiguration.Builder()
                    .requiredDistanceInterval(4)
                    .acceptableAccuracy(1.0f)
                    .requiredTimeInterval(1000)
                    .acceptableTimePeriod(1000)
                    .setWaitPeriod(ProviderType.GPS,  4000)
                    .setWaitPeriod(ProviderType.NETWORK,  4000).build())
            .build();
}

Finally i have to let you know a user case scenaio LocationRequest locationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY if i use this PRIORITY_BALANCED_POWER_ACCURACY then if i switch off internet ,locatin still on ,and restart app then i wont get location because the balanced power will make it to use batter saving option in location services and it wont use gps one so in conclusion the only option left to work is LocationRequest.PRIORITY_HIGH_ACCURACY) with adjustable setInterval

i have also converted your release "2.0.4" to android x and added two wonderful methods inside LocationBaseFragment to change configuartion dynamically

    protected void enableNavigationLocationManager(){
    locationManager.cancel();
    locationManager = null;
    locationManager = new LocationManager.Builder(getContext().getApplicationContext())
            .configuration(Utils.navigationConfiguration())
            .fragment(this)
            .notify(this)
            .build();
    locationManager.get();
  }

     protected void disableNavigationLocationManager(){
    locationManager.cancel();
    locationManager = null;
    locationManager = new LocationManager.Builder(getContext().getApplicationContext())
            .configuration(Utils.defaultConfiguration())
            .fragment(this)
            .notify(this)
            .build();
    locationManager.get();
  }

where Utils.defaultConfiguration() is written above and Utils.navigationConfiguration() is --

   public static LocationConfiguration navigationConfiguration() {
    LocationRequest locationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(2000).setFastestInterval(1000).setSmallestDisplacement(1);

    //google play services configuration
    GooglePlayServicesConfiguration gpsc = new GooglePlayServicesConfiguration.Builder()
            .locationRequest(locationRequest)
            .fallbackToDefault(true)
            .askForGooglePlayServices(true)
            .askForSettingsApi(true)
            .ignoreLastKnowLocation(true)
            .setWaitPeriod(4000)
            .build();

    return new LocationConfiguration.Builder()
            .keepTracking(true)
            .useGooglePlayServices(gpsc)
            .useDefaultProviders(new DefaultProviderConfiguration.Builder()
                    .requiredDistanceInterval(4)
                    .acceptableAccuracy(1.0f)
                    .requiredTimeInterval(1000)
                    .acceptableTimePeriod(1000)
                    .setWaitPeriod(ProviderType.GPS,  4000)
                    .setWaitPeriod(ProviderType.NETWORK,  4000).build())
            .build();
}
yayaa commented 4 years ago

I understand, but unfortunately what you describe sounds more like GooglePlayServices issues than this library. Please note that this library is only a wrapper around all the functionalities to provide a simple API to retrieve location, but under the hood, it still talks to the APIs provided by framework. That being said, I'll close this issue, feel free to re-open if you have more information that is caused by the library but not the framework or GooglePlayServices itself.

About LocationBaseFragment and adding functionalities - that class is only to showcase how to use it, you might create your own implementation, of course. But from the code you showed, I would like to correct this part "change configuration dynamically", you are not changing the configuration - which is built immutable by the library in purpose to avoid unreliable and unexpected behaviours, you are just creating a new instance with different configuration - which is totally fine.

officialtanuj commented 4 years ago

I understand, but unfortunately what you describe sounds more like GooglePlayServices issues than this library. Please note that this library is only a wrapper around all the functionalities to provide a simple API to retrieve location, but under the hood, it still talks to the APIs provided by framework. That being said, I'll close this issue, feel free to re-open if you have more information that is caused by the library but not the framework or GooglePlayServices itself.

About LocationBaseFragment and adding functionalities - that class is only to showcase how to use it, you might create your own implementation, of course. But from the code you showed, I would like to correct this part "change configuration dynamically", you are not changing the configuration - which is built immutable by the library in purpose to avoid unreliable and unexpected behaviours, you are just creating a new instance with different configuration - which is totally fine.

I totally agree and concur with you i was just sharing the code which is in production version and has been tested on 7 different devices so i thought the configuration (to keep min 4 seconds in waiting time ,as it didnt work in 3 secoonds) might help beginners/someone to help jump start the app

again what you said is right thank you for creating the lib cheers and Happy New Year