导航
  • 主页
  • 招聘
  • 音视频
  • Camera
  • UI
  • 协议
  • SDK
  • NDK
  • Flutter
  • ADB
  • Android Studio
  • 模拟器
  • 问答

LocationListener无法触发onStatusChanged事件

山娃马小三儿 2011-09-03 05:28:05
不是在模拟器运行的,是在真机器上,gps开始搜索信号,直到可以在onLocationChanged中得到经纬度信息,然后把机器拿到房间里,gps信号中断,整个过程写在onStatusChanged里的事件一次也不触发
...全文
722 点赞 收藏 11
写回复
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangxiangpi 2011-12-09
wen ti jie jue le ma lou zhu
回复
ben278604 2011-11-16
是不是因为没有加tag:@Override
回复
ben278604 2011-11-16
是不是
回复
sdzbsj 2011-11-08
如果开发GPS应用方面的软件
①先要获取一个管理器:
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
②再定义一个监听:
LocationListener locationListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
switch (status) {
// GPS状态为可见时
case LocationProvider.AVAILABLE:
Log.e("TAG", "当前GPS状态为可见状态");
et01.setText("LocationProvider.AVAILABLE");
break;
// GPS状态为服务区外时
case LocationProvider.OUT_OF_SERVICE:
Log.e("TAG", "当前GPS状态为服务区外状态");
et01.setText("LocationProvider.OUT_OF_SERVICE");
break;
// GPS状态为暂停服务时
case LocationProvider.TEMPORARILY_UNAVAILABLE:
Log.e("TAG", "当前GPS状态为暂停服务状态");
et01.setText("LocationProvider.TEMPORARILY_UNAVAILABLE");
break;
}
}

@Override
public void onProviderEnabled(String provider) {
Log.e("TAG", "onProviderEnabled");
et01.setText("onProviderEnabled");
}

@Override
public void onProviderDisabled(String provider) {
Log.e("TAG", "onProviderDisabled");
et01.setText("onProviderDisabled");
}

@Override
public void onLocationChanged(Location location) {
// updateView(location);
Log.e("TAG", "时间:" + location.getTime());
Log.e("TAG", "经度:" + location.getLongitude());
Log.e("TAG", "纬度:" + location.getLatitude());
Log.e("TAG", "海拔:" + location.getAltitude());
et01.setText("时间:" + location.getTime() + "经度:" + location.getLongitude() + "纬度:"
+ location.getLatitude() + "海拔:" + location.getAltitude());
}
};
③邦定监听到管理器上(provider直接使用GPS_PROVIDER,不考虑NETWORK_PROVIDER):
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

问题是,测试时(真实设备非虚拟设备),似乎永远无法触发locationListener的onStatusChanged方法,请教高手,何时能触发这个方法,再就解释一下方法中的各个状态,多谢!!!
回复
sdzbsj 2011-11-08
我也碰到这个问题,困惑许久了
回复
momogenyun 2011-09-24
I have defined LocationListener like this one and set through requestLocationUpdates() for both providers GPS and NETWORK.

public class geoListener implements LocationListener {
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("test", "Status changed to " + status);
}

public void onLocationChanged(Location location) {
// do some things
}
}

What happend ON REAL DEVICE:
- Nothing. onStatusChanged is never called. Not when GPS gets fixed, not when GPS lost fix... just never. Other methods (eg. onLocationChanged) of used LocationListener are working properly.

What happend ON EMULATOR:
- onStatusChanged is called when I manually set location using ddms.

Expecting behavior ON REAL DEVICE:
- onStatusChanged should be called everytime the provider changed status between available or unavailable (temporarily or permanently). For example when GPS gets or lost fix.

Operating system ON REAL DEVICE:
- Android 2.2, FRF85B, Google Nexus One
Comment 1 by LetsF...@gmail.com, Aug 12, 2010 I'm also experiencing this issue, on a HTC Desire, Android 2.2
Comment 2 by jai.chan...@gmail.com, Sep 20, 2010 I am also facing the same issue on my Nexus one, Android 2.2
Comment 3 by digist...@gmail.com, Oct 9, 2010 This issue is also present on Android 2.2.1, build FRG83 on a Nexus One.
Comment 4 by davidsma...@gmail.com, Feb 10, 2011 Same behavior on Nexus S. LocationListener is registered but onStatusChanged is never called.
Nexus S Android 2.3.1
Kernel Version 2.6.35.7-g7f1638a
Build Number GRH78

OnStatusChanged DOES get called on the Samsung Galaxy S running 2.1
Comment 5 by pika...@gmail.com, Feb 20, 2011 Same issue on SH-03C, Android 2.1-update1.
OnStatusChanged does NOT get called.
Comment 6 by kurle...@gmail.com, May 19, 2011 Exactly the same issue on HTC Desire Android 2.2
onStatusChanged is not called.
Comment 8 by dutchtap...@gmail.com, Jul 28, 2011 Same issue on Samsung Galaxy S running 2.2
Comment 10 by dutchtap...@gmail.com, Aug 3, 2011 Updated to 2.3.3, still the same
Also tested on Galaxy S 2 with 2.3.3, no luck.
Also tested on old G1 HTC 1.6, it works on that device.

Strange..
Comment 11 by galandil...@gmail.com, Aug 6, 2011 On Nexus One 2.3.4 onStatusChanged is not called too - what is more interesting it did work on Android 1.6

other finding:
after acquiring GpsSatellite objects from GpsStatus none of them have isUsedInFix set to false
回复
谁给指点一下
回复
[Quote=引用 2 楼 kechanghe0705 的回复:]
可能是你设置onStatusChanged事件的最短距离或最短时间比较大,所以从有经纬度到房间那段距离还不够
[/Quote]

这个跟有经纬度有关系吗,不是onlocationchange啊是onStatusChanged
回复
傲慢的上校 2011-09-06
[Quote=引用 2 楼 kechanghe0705 的回复:]

可能是你设置onStatusChanged事件的最短距离或最短时间比较大,所以从有经纬度到房间那段距离还不够
[/Quote]
回复
_Jung_ 2011-09-06
可能是你设置onStatusChanged事件的最短距离或最短时间比较大,所以从有经纬度到房间那段距离还不够
回复
没人遇到过吗?
回复
发动态
发帖子
Android
创建于2009-10-09

7.8w+

社区成员

移动平台 Android
申请成为版主
社区公告
暂无公告