I need to use requestLocationUpdates() to get location update when some specified distance traveled or for some particular distance.
I need this to be updated on distance basis only and not time basis.
开发者_运维问答Please suggest....
The documentation has a good answer.
public void requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener)
If minDistance is greater than 0, a location will only be broadcasted if the device moves by minDistance meters. To obtain notifications as frequently as possible, set both parameters to 0.
The location change will be detected by OnLocationChange()
called by the LocationListener
registered at requestLocationUpdates()
.
To ignore the time delay in between location requests just specify it as 0. This way it is 0 seconds delay which really means no delay.
LocationManager yourLoc = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
yourLoc.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, onLocationChange);
The above example changes at every 1m.
try setting the minTime parameter to max value of an Integer or float in java, that way it will get called by minDistance prior to minTime
精彩评论