手动添加位置更新在Eclipse中停止工作 [英] Manually added location updates stop working in Eclipse

查看:97
本文介绍了手动添加位置更新在Eclipse中停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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方法中添加了一些日志记录,只有看到我尝试发送更新的第一个时间。所有后续的不会触发onLocationChanged方法。



附加信息:



logcat输出如下:

  10-02 17:22:34.423:INFO / gps(6671):提供者gps的状态已更改为1。其他:捆绑[mParcelledData.dataSize = 52] 

首次GPS更新是伪造的:

  10-02 17:22:49.383:INFO / gps(6671):位置提供商提供的位置:位置[mProvider = gps,mTime = 1000,mLatitude = 25.0,mLongitude = 23.0,mHasAltitude =真,mAltitude = 0.0,mHasSpeed =假,MSPEED = 0.0,mHasBearing =假,mBearing = 0.0,mHasAccuracy =假,mAccuracy = 0.0,mExtras =捆绑[mParcelledData.dataSize = 52]] 
10-02 17:22:49.444:INFO / gps(6671):提供者gps的状态已更改为2.其他:捆绑[mParcelledData.dataSize = 52]

根据 http:// deve loper.android.com/reference/android/location/LocationProvider.html#AVAILABLE ,该图贴图可用。



一旦可用设置,没有其他位置通过。似乎有点违反直觉。

解决方案

我相信你在仿真器的GPS驱动程序中遇到了一个错误。 b
$ b

1.5版SDK的解决方法包含在错误报告。从那里引用:


在模拟器中,在主屏幕上,按菜单 - >设置 - >
日期和时间 - >取消选中自动 - >选择时区,
并选择正确的时区(即您的)。


A 修复包含在1.6版本的SDK中。


I'm working on a 1.5 Android application. Developing in Eclipse 3.4.2 on Windows XP. I have a MapView, have requested updates, etc.

The problem is that after the first manually injected GPS coordinate, the app stops recognizing that a GPS coord has been sent.

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);   

Then MyLocationListener simply changes the value in a TextView to match the new GPS coordinate.

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);

    }

I added some logging in the onLocationChanged method and it only ever sees a Location the first time that I attempt to send an update. All subsequent ones don't fire the onLocationChanged method.

Additional info:

The logcat output is as follows:

10-02 17:22:34.423: INFO/gps(6671): Provider gps is has status changed to 1. Extras: Bundle[mParcelledData.dataSize=52]

First GPS update is faked:

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]

According to http://developer.android.com/reference/android/location/LocationProvider.html#AVAILABLE , that 2 maps to "Available".

As soon as that "Available" gets set, no other locations get passed through. Seems a bit counterintuitive.

解决方案

I believe you are experiencing a bug in the GPS driver of the emulator.

A workaround for the 1.5 versions of the SDK is included in the bug report. To quote from there:

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 is included in the 1.6 release of the SDK.

这篇关于手动添加位置更新在Eclipse中停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆