我正在开发 1.5 Android 应用程序。在 Windows XP 上的 Eclipse 3.4.2 中开发。我有一个 MapView,已请求更新等。
问题是,在第一次手动输入 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 方法中添加了一些日志记录,它只会在我尝试发送更新时第一次看到一个 Location。所有后续的都不会触发 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。
In the emulator, on the Home Screen, press
Menu -> Settings -> Date & Time -> (Uncheck )Automatic -> Select Time Zone
and choose the right time zone (ie, yours).
A fix包含在 SDK 的 1.6 #43 版本中。
关于android - 手动添加的位置更新在 Eclipse 中停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1509958/