Why is Location manager's minimum update time overridden when location changes?
I'm developing a mapping 开发者_如何学Pythonapp 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();
}
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?
精彩评论