I am trying to use the Smart Location Library to obtain periodic location updates. But when start the process it fires the listener once then there is no further updates. Here is the code i used
public void startTracking(View v) {
provider = new LocationGooglePlayServicesWithFallbackProvider(this);
Log.i("Tag","Start Tracking");
SmartLocation smartLocation = new SmartLocation.Builder(this)
.logging(true)
.build();
smartLocation.location(provider)
.config(LocationParams.BEST_EFFORT)
.start(this);
smartLocation.activity().start(this);
}
public void stopTracking(View v) {
Log.i("Tag","Stop Tracking");
SmartLocation.with(this).location().stop();
SmartLocation.with(this).activity().stop();
}
@Override
public void onActivityUpdated(DetectedActivity detectedActivity)
{
Log.i("Tag","ActivityUpdate : "+detectedActivity.toString());
}
@Override
public void onLocationUpdated(Location location)
{
Log.i("Tag","LocationUpdate : "+location.getLatitude()+","+location.getLongitude());
}
This is the Logcat output I got
01-27 14:09:01.791 3038-3038/com.angulusits.smartlocationtest I/Tag:
Start Tracking
01-27 14:09:01.879 3038-3038/com.angulusits.smartlocationtest I/Tag:
ActivityUpdate : DetectedActivity [type=STILL, confidence=100]
01-27 14:09:02.017 3038-3038/com.angulusits.smartlocationtest I/Tag:
LocationUpdate : <some-value>,<some-value>
This is given as soon as i press startButton, Then no more values.
I checked the code on the Library for BEST_EFFORT value which is :
public static final LocationParams BEST_EFFORT = new Builder().setAccuracy(LocationAccuracy.MEDIUM).setDistance(150).setInterval(2500).build();
So I expected updates every 2500 millisecs even if device is not moving. I would appreciate if someone can point me in the right direction.
You need to say continuous()
while creating the location listener.
Try this code snippet below,
private void startLocationListener() {
long mLocTrackingInterval = 1000 * 5; // 5 sec
float trackingDistance = 0;
LocationAccuracy trackingAccuracy = LocationAccuracy.HIGH;
LocationParams.Builder builder = new LocationParams.Builder()
.setAccuracy(trackingAccuracy)
.setDistance(trackingDistance)
.setInterval(mLocTrackingInterval);
SmartLocation.with(this)
.location()
.continuous()
.config(builder.build())
.start(new OnLocationUpdatedListener() {
@Override
public void onLocationUpdated(Location location) {
processLocation(location);
}
});
}
Its late reply! Anyway this would help someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With