Manually updated updates stop working in Eclipse
I am working on 1.5 android app. Development in Eclipse 3.4.2 on Windows XP. I have a MapView, requested updates, etc.
The problem is that after the first manually entered GPS coordinate, the app stops recognizing that a GPS coordinate 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 just changes the value in the 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've added a few protocols to the onLocationChanged method and it only ever sees the location the first time I try to send an update. All subsequent ones do not trigger onLocationChanged method.
Additional Information:
The logcat output looks like this:
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 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 , this 2 corresponds to "Available".
Once set to Available, no other locations will pass. Seems a bit controversial.
source to share
I believe you are experiencing a bug in the GPS emulator driver.
Workaround for SDK 1.5 from Google Issue Tracker # 39 .
In the emulator on the home screen, click
Menu โ Settings โ Date and time โ (Uncheck the box) Automatic โ Select time zone
and choose the correct timezone (i.e. yours).
A fix is included in SDK 1.6 # 43.
source to share