android – requestLocationUpdates中的update interval

前端之家收集整理的这篇文章主要介绍了android – requestLocationUpdates中的update interval前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何更新时间和距离间隔,或者以不同的间隔再次调用requestLocationUpdates?

我的代码

LocationManager locationManager = (LocationManager) activityObject.getSystemService(Context.LOCATION_SERVICE);

    cll = new CheckinLocationListener();

    LocationProvider gps = locationManager.getProvider(LocationManager.GPS_PROVIDER);

    // GPS

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,timeDelay,distanceDelay,cll);

    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

onLocationChanged:

if(location.getSpeed()>=0 && location.getSpeed()<= 3)
            {
                LocationsModel.this.distanceDelay = 25;
                LocationsModel.this.timeDelay = 10000;
            }
            else if(location.getSpeed()>=3 && location.getSpeed()<= 17)
            {
                LocationsModel.this.distanceDelay = 150;
                LocationsModel.this.timeDelay = 60000;
            }
            else if(location.getSpeed()>=17)
            {
                LocationsModel.this.distanceDelay = 300;
                LocationsModel.this.timeDelay = 240000;
            }

我想在下一个措施中使用新的时间间隔.

解决方法

您需要先调用locationManager.removeUpdates(cll);然后使用新的间隔重新注册更新.
原文链接:https://www.f2er.com/android/316031.html

猜你在找的Android相关文章