views:

112

answers:

1

Hi folks,

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.

+2  A: 

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.

Rene
I haven't tested your answer yet but the bug report you gave is an excellent resource. I'm glad to find I'm not the only one with this problem!Interestingly enough, my coworker on a Mac does not have this issue.
I82Much
Just tested your solution and it works brilliantly.I never in a million years would have thought of a link between GPS coordinates and automatically managed time zone settings...
I82Much