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.