requestLocationUpdates 中的更新间隔
如何更新时间和距离间隔,或以不同的间隔再次调用 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;
}
我想在下一次测量中使用新的间隔。
How can I update time and distance intervals, or call requestLocationUpdates again with different intervals?
My code:
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;
}
I would like to use the new intervals at the next measure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要首先调用
locationManager.removeUpdates( cll );
,然后使用新的时间间隔重新注册更新。You'll need to first call
locationManager.removeUpdates( cll );
and then re-register for updates using your new interval.