1
             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米的距离,但是程序启动时请求立即更新并调用位置改变函数我可以忽略位置改变函数直到到达距离吗?

4

1 回答 1

0

试试这个(未经测试,但基于文档):

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) { }
}
于 2012-11-14T03:10:06.313 回答