手动添加的位置更新停止在Eclipse中工作
问题描述:
我正在研究1.5 Android应用程序。在Windows XP上的Eclipse 3.4.2中进行开发。我有一个MapView,请求更新等。手动添加的位置更新停止在Eclipse中工作
问题是,在第一次手动注入GPS坐标后,应用程序停止识别GPS坐标已发送。
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
MapController mc = mapView.getController();
TextView locationText = (TextView) findViewById(R.id.LocationBar);
LocationListener locationListener = new MyLocationListener(mc, itemizedOverlay, locationText);
lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
locationListener);
然后MyLocationListener只是改变TextView中的值以匹配新的GPS坐标。
public void onLocationChanged(Location loc) {
if (loc == null) {
return;
}
double lat = loc.getLatitude();
double lng = loc.getLongitude();
GeoPoint p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
itemizedOverlay.addOverlay(new OverlayItem(p, "title", "snippet"));
String location = String.format("%f lat %f long", lat, lng);
locationText.setText(location);
}
我加了一些记录在onLocationChanged方法,它永远只看到某个位置上第一一次,我尝试发送更新。所有后续的不会触发onLocationChanged方法。
附加信息:
的logcat的输出如下所示:
10-02 17:22:34.423: INFO/gps(6671): Provider gps is has status changed to 1. Extras: Bundle[mParcelledData.dataSize=52]
第一GPS更新伪造:
10-02 17:22:49.383: INFO/gps(6671): Location provided by location provider: Location[mProvider=gps,mTime=-1000,mLatitude=25.0,mLongitude=23.0,mHasAltitude=true,mAltitude=0.0,mHasSpeed=false,mSpeed=0.0,mHasBearing=false,mBearing=0.0,mHasAccuracy=false,mAccuracy=0.0,mExtras=Bundle[mParcelledData.dataSize=52]]
10-02 17:22:49.444: INFO/gps(6671): Provider gps is has status changed to 2. Extras: Bundle[mParcelledData.dataSize=52]
根据http://developer.android.com/reference/android/location/LocationProvider.html#AVAILABLE,即2名映射到 “可用”。
只要“可用”被设置,其他位置就不会通过。看起来有点违反直觉。
答
我相信你正在遇到模拟器的GPS驱动程序中的错误。
1.5版SDK的解决方法是从Google Issue Tracker#39。
在模拟器中,在主屏幕,按
菜单 - >设置 - > 日期&时间 - >(选中)自动 - >选择时区
,并选择合适的时机区域(即你的)。
A fix包含在SDK的1.6#43版本中。
通过telnet通过geo fix命令发送GPS位置会体现同样的问题......只有第一次位置更新才会被听到。 – I82Much 2009-10-02 14:53:55