位置管理器的 requestLocationUpdates 仅调用一次
我正在调用该方法并期望位置更新多次:
locationManager.requestLocationUpdates("gps",0 ,0, loc_listener);
我的 loc_listener
定义为:
LocationListener loc_listener = new LocationListener() {
private final String TAG = "xoxoxo.LocationListener";
public void onLocationChanged(Location l) {
Intent locationAlert = new Intent("xoxoxo.LOCATION_CHANGED")
.putExtra("target_location", l);
sendBroadcast(locationAlert);
// locationManager.requestLocationUpdates("gps", 0 ,0, this);
}
public void onProviderEnabled(String p) {
Log.i(TAG, "Provider enabled");
}
public void onProviderDisabled(String p) {
Log.i(TAG, "Provider disabled");
}
public void onStatusChanged(String p, int status, Bundle extras) {
Log.i(TAG, "Status changed");
}
};
按原样定义,我只会在 HTC Evo 2.2 和 2.2 + Google API 模拟器上获得一次更新。 获取多个更新的方法是取消注释每次更新时注册更新的行:
locationManager.requestLocationUpdates("gps", 0 ,0, this);
你们见过这样的东西吗?
I am calling the method and expect location updates multiple times:
locationManager.requestLocationUpdates("gps",0 ,0, loc_listener);
My loc_listener
is defined as:
LocationListener loc_listener = new LocationListener() {
private final String TAG = "xoxoxo.LocationListener";
public void onLocationChanged(Location l) {
Intent locationAlert = new Intent("xoxoxo.LOCATION_CHANGED")
.putExtra("target_location", l);
sendBroadcast(locationAlert);
// locationManager.requestLocationUpdates("gps", 0 ,0, this);
}
public void onProviderEnabled(String p) {
Log.i(TAG, "Provider enabled");
}
public void onProviderDisabled(String p) {
Log.i(TAG, "Provider disabled");
}
public void onStatusChanged(String p, int status, Bundle extras) {
Log.i(TAG, "Status changed");
}
};
Defined as is, I will only get an update once, both on HTC Evo 2.2 and 2.2 + Google API emulator.
The hack to get multiple updates is to uncomment the line which registers for updates on each update:
locationManager.requestLocationUpdates("gps", 0 ,0, this);
Have you guys seen anything like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从来没有见过这个问题。以下是我测试 LocationManager 和 LocationListener 的代码。当 LocationListener 作为匿名类实现时,它会按预期工作。
I have never seen the issue. The following is my code to test LocationManager and LocationListener. It works as expected when LocationListener is implemented as an anonymous class.