Improve network location finder

This commit is contained in:
Victor Shcherb 2011-09-04 14:16:30 +03:00
parent 820ccee4d0
commit 028891c847

View file

@ -88,6 +88,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
private static final int SHOW_POSITION_MSG_ID = 7;
private static final int SHOW_POSITION_DELAY = 2500;
private static final float ACCURACY_FOR_GPX_AND_ROUTING = 50;
@ -517,7 +518,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
}
if(location != null && settings.SAVE_TRACK_TO_GPX.get()){
// write only with 50 meters accuracy
if (!location.hasAccuracy() || location.getAccuracy() < 50) {
if (!location.hasAccuracy() || location.getAccuracy() < ACCURACY_FOR_GPX_AND_ROUTING) {
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(),
location.getAccuracy(), location.getTime(), settings);
}
@ -526,8 +527,11 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
updateSpeedBearing(location);
mapLayers.getLocationLayer().setLastKnownLocation(location);
if(routingHelper.isFollowingMode()){
if(location == null ||
!location.hasAccuracy() || location.getAccuracy() < ACCURACY_FOR_GPX_AND_ROUTING) {
routingHelper.setCurrentLocation(location);
}
}
if (location != null) {
if (isMapLinkedToLocation()) {
if(settings.AUTO_ZOOM_MAP.get() && location.hasSpeed()){
@ -676,15 +680,13 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
if (LocationProvider.OUT_OF_SERVICE == status) {
// do not use it in routing
if (!useOnlyGPS() && service.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
// try enable network listener
try {
service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST,
networkListener);
} catch (IllegalArgumentException e) {
Log.d(LogUtil.TAG, "Network location provider not available"); //$NON-NLS-1$
}
// service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, this);
if (service.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
// try {
// service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST,
// networkListener);
// } catch (IllegalArgumentException e) {
// Log.d(LogUtil.TAG, "Network location provider not available"); //$NON-NLS-1$
// }
}
} else if (LocationProvider.AVAILABLE == status) {
// Do not remove right now network listener
@ -795,14 +797,12 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
} catch (IllegalArgumentException e) {
Log.d(LogUtil.TAG, "GPS location provider not available"); //$NON-NLS-1$
}
if(!useOnlyGPS()){
// try to always ask for network provide : it is faster way to find location
try {
service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, networkListener);
} catch(IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
Log.d(LogUtil.TAG, "Network location provider not available"); //$NON-NLS-1$
}
}
if(settings != null && settings.isLastKnownMapLocation()){