mrmans0n / smart-location-lib

Android library project that lets you manage the location updates to be as painless as possible
1.65k stars 353 forks source link

Any Sample code for using location update while in DetectedActivity.VEHICLE #224

Open rasheedk opened 6 years ago

rasheedk commented 6 years ago

Now coming to the issue / problem now facing: How to use this location updates while walking in my method. please note that i have implemented OnLocationUpdatedListener in the Activity

`

private void startLocation() {

    provider = new LocationGooglePlayServicesProvider();
    provider.setCheckLocationSettings(true);
    SmartLocation smartLocation = new SmartLocation.Builder(this).logging(true).build();
    smartLocation.location(new LocationBasedOnActivityProvider(**call back**).config(LocationParams.NAVIGATION).start(this);

}

`

What is this call back.

or can u post a sample code , how to use this location updates while walking or running... etc like that....

rasheedk commented 6 years ago

Finally got the code:


SmartLocation.with(this).location(new LocationBasedOnActivityProvider(new LocationBasedOnActivityProvider.LocationBasedOnActivityListener() {
    @Override
    public LocationParams locationParamsForActivity(DetectedActivity detectedActivity) {
        if (detectedActivity.getConfidence() >= 75) {
            LocationParams.Builder builder = new LocationParams.Builder();
            switch (detectedActivity.getType()) {
                case DetectedActivity.IN_VEHICLE:
                    builder.setInterval(/*Interval*/)
                            .setAccuracy(/*Locaiton Accuracy*/);
                    break;

                case DetectedActivity.ON_BICYCLE:
                    /* So on and so forth.... */

                    break;
            }
            return builder.build();
        }
        return null;
    }
})).start(new OnLocationUpdatedListener() {
    @Override
    public void onLocationUpdated(Location location) {
        //Do what you need here.
    }
});