【发布时间】:2014-07-07 03:19:15
【问题描述】:
大家好,我创建了一个后台服务来获取人员位置,如果设备与目的地之间的距离更小,我会更频繁地请求位置更新,我正在使用 removeUpdates(LocationListener) 方法...问题是我注意到侦听器不断获得更新,并且循环越多,它就会不断获得越来越多的更新。有谁知道为什么这种方法不起作用?
这是我使用新位置的方法。
void makeUseOfNewLocation(Location location){
manager.removeUpdates(listener);
mLocation = location;
currentLat = location.getLatitude();
currentLong = location.getLongitude();
Location.distanceBetween(currentLat, currentLong, gateLat, gateLong, results);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
currentDistanceFromDestination = results[0];
Log.d("Current Location", "Lat:"+currentLat+" Long:"+currentLong);
Log.d("Destination Distance", currentDistanceFromDestination+"");
if(currentDistanceFromDestination<3000){
if(currentDistanceFromDestination<50){
Log.d("50m closer", "Calling");
startActivity(callIntent);
stopSelf();
}
if(currentDistanceFromDestination<800){
Log.d("800m closer", "Started listening every 10 seconds.");
Toast.makeText(getApplicationContext(),currentDistanceFromDestination+"", Toast.LENGTH_LONG).show();
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10 ,90 , listener);
}else{
Log.d("3000m closer", "Started listening every 25 seconds");
Toast.makeText(getApplicationContext(),currentDistanceFromDestination+"", Toast.LENGTH_LONG).show();
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 25 * 1000, 300, listener);
}
}
}
【问题讨论】:
-
它可能会再次开始收听更新,因为你有
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 25 * 1000, 300, listener); -
hmmm ye 它假设会听,它会这样做,但它不会删除任何更新
-
你能把整个代码贴出来吗?
标签: android gps listener locationmanager