views:

27

answers:

1

I'm developing a mapping app using Eclipse 3.5.

I'm setting the minimum update period with the LocationManager's requestLocationUpdates method, via a configuration activity. When I set the property I see in Logcat that the system process sets the value OK.

When I actually send a new location from the DDMS emulator control and the location changes on the map view, I see that the system process then sets the minimum time to zero.

Below is a capture of the system's log messages. You can see that I'm setting the period to 32 seconds, then 16, then, after I've sent a simulated location change the system sets it to zero

The map responds to location changes to location changes instantly even if they are sent only a couple of seconds apart.

Does anyone know why my minimum time is overridden by the system?

10-26 22:21:09.770: DEBUG/GpsLocationProvider(54): setMinTime 32000
10-26 22:21:53.011: DEBUG/GpsLocationProvider(54): stopNavigating
10-26 22:21:57.810: DEBUG/GpsLocationProvider(54): setMinTime 16000
10-26 22:21:57.810: DEBUG/GpsLocationProvider(54): startNavigating
10-26 22:21:57.900: DEBUG/GpsLocationProvider(54): setMinTime 16000
10-26 22:22:39.099: DEBUG/GpsLocationProvider(54): TTFF: 41290
10-26 22:22:39.350: DEBUG/GpsLocationProvider(54): setMinTime 0
10-26 22:22:51.740: DEBUG/GpsLocationProvider(54): TTFF: 53925
10-26 22:22:51.820: DEBUG/GpsLocationProvider(54): setMinTime 0
10-26 22:22:56.780: DEBUG/GpsLocationProvider(54): TTFF: 58967
10-26 22:22:56.879: DEBUG/GpsLocationProvider(54): setMinTime 0

pertinent code, below, enableGPS() called in onResume()

    private void enableGPS() {

    if (confData.getTrackMode() == AppConstants.GPS_ON) {
        if (lm == null)
            lm = (LocationManager) getSystemService(LOCATION_SERVICE);
        long updateMillis = confData.getMapUpdatePeriod() * 1000;
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                updateMillis, confData.getMapMinResendDistance(), this);
    }

}

and listener is

    public void onLocationChanged(Location location) {

    List<Overlay> overlays = mv.getOverlays();
    lo = new MyLocationOverlay(this, mv);
    overlays.add(lo);
    lo.enableMyLocation();
    int lat = (int) (location.getLatitude() * 1E6);
    int lng = (int) (location.getLongitude() * 1E6);
    GeoPoint point = new GeoPoint(lat, lng);
    mc.setCenter(point);
    mv.invalidate();
}
A: 

First, android GPS use with emulator is really full of bugs, I try all aps with a real phone if it involves using GPS when I get inconsistent behaiviour.

Taken from the Android Reference:

public void requestLocationUpdates (String provider, long minTime, float minDistance, PendingIntent intent)

minTime the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value.

Edit, i saw this in your code:

long updateMillis = confData.getMapUpdatePeriod() * 1000;

Im guessing this is just something that returns a constant? Or is it an android method? why not just set it at 60000 or soemthing like that manually?

blindstuff
I'd seen this and knew it was 'just a hint'. It seemed to take the hint until the location actually changed. I seem to remember that at sometime in the past, this did work in the emulator, i.e updates sent before the minimum time were ignored. I can't prove it though and I'm not about to roll back SDK/plugin versions. I do take your point about it being buggy - it can't even pass on the simulated location being sent without introducing a significant rounding error!
NickT
Added something to my answer.If you have how to do it, hook a phone to a laptop and walk around looking at the DDMS, also set the min distance to 0 while testing, see how often it gets called an at least you can decide wether its a real problem or just an emulator problem.
blindstuff
I have tried hard coding it, it makes no difference. I was logging the value just to make sure it wasn't zero. The value comes out of saved preferences and is user configurable. I haven't actually got a phone, so I'm trying to work out a power saving regime, before I send the apk to a friend who has. I don't want to flatten his battery straight away!
NickT
Sorry, im out of ideas then.
blindstuff