Problem seems to be solved.
In onCreate, I added:
Criteria crit = new Criteria();
crit.setAccuracy(Criteria.ACCURACY_FINE);
best = mgr.getBestProvider(crit, false);
mgr.requestLocationUpdates(best, 0, 1, locationListener);
onLocationChanged now looks like that:
@Override
public void onLocationChanged(Location location) {
i++;
nextPoint = overlay.getMyLocation();
latitude = nextPoint.getLatitudeE6();
longtitude = nextPoint.getLongitudeE6();
lastPoint = new GeoPoint((int) latitude, (int) longtitude);
Points.add(lastPoint);
MapOverlay mapOverlay = new MapOverlay(Points.get(i - 1), Points.get(i));
map.getOverlays().add(mapOverlay);
mMapController.animateTo(Points.get(i));
nextPoint = null;
lastPoint = null;
}
Also, very important methods:
@Override
protected void onResume() {
super.onResume();
mgr.requestLocationUpdates(best, 10000, 1, locationListener);
}
@Override
protected void onPause() {
super.onPause();
mgr.removeUpdates(locationListener);
}
And also some new permissions:
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…