我可以停止位置更新,直到距离达到?

时间:2012-11-14 02:40:45

标签: android android-location

             LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

             LocationListener ll = new mylocationlistener();


               lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, ????, 20, ll);

1.如果仅应用minDistance(20m),我应该输入什么minTime参数? 0,-1还是100000000?

2.顺便说一下,我想提示用户已经到达距离原始地方20米的距离,但是当程序启动并调用位置改变功能时请求立即更新我可以忽略位置改变功能直到距离达到?

1 个答案:

答案 0 :(得分:0)

尝试此操作(未经测试,但基于the docs):

final LocationManager locationManager =  LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
class implements LocationListener {
    Location storedLocation;
    public void onLocationChanged(Location newLocation) {
        if (storedLocation.equals(null)) {
            storedLocation = newLocation;
        }
        if ((newLocation.distanceTo(storedLocation) > 20.0) { 
            locationManager.removeUpdates(self);   
            return;
        }
        storedLocation = newLocation;
    }
    public void onProviderDisabled(String provider) { }
    public void onProviderEnabled(String provider) { }
    public void onStatusChanged(String provider, int status, Bundle extras) { }
}