Issue
I have a situation like the following:
If car is stationary(not moving) than i want to call location update api after every 5min. If car is moving than i want to call location update api after every 2min.
or
If car keep moving 2000 meters distance than need to call location update api after every 5min.Actually how to check that location is same or not?
Solution
You can receive Information about location changes with the Location Update Callback
. Read more about it in the android developer docs. Here is a basic example on how you can detect if the location changed:
public class MainActivity extends ActionBarActivity implements LocationListener {
private Location mLastKnownLocation;
...
@Override
public void onLocationChanged(Location location) {
//location changed
mLastKnownLocation = location
}
}
}
Basically you just receive information about the current location if the location changed.
So in your case where you want to know every 5 min / 2 min if the location changed implement a timer, loop, etc. to check every 5 min / 2 min if you received a locationChangedEvent and the location changed or not
Answered By - IIIIIIIIIIIIIIIIIIIIII
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.