diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java index 6ebe1645ee..43f512b448 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java @@ -513,7 +513,7 @@ public class RouteSegmentResult implements StringExternalizable return endPointIndex - startPointIndex > 0; } - + private LatLon convertPoint(RouteDataObject o, int ind){ return new LatLon(MapUtils.get31LatitudeY(o.getPoint31YTile(ind)), MapUtils.get31LongitudeX(o.getPoint31XTile(ind))); } diff --git a/OsmAnd/res/values-ru/phrases.xml b/OsmAnd/res/values-ru/phrases.xml index 52a4d7e108..977539c77f 100644 --- a/OsmAnd/res/values-ru/phrases.xml +++ b/OsmAnd/res/values-ru/phrases.xml @@ -1759,7 +1759,7 @@ Топливо 91UL Топливо 100LL Топливо Jet A-1 - Топливо AdBlue + Дизельная выхлопная жидкость Топливо: дрова Топливо: древесный уголь Топливо: каменный уголь diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 8f17f06190..d860838c4f 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -671,50 +671,35 @@ public class OsmandAidlApi { public void onReceive(Context context, Intent intent) { MapActivity mapActivity = mapActivityRef.get(); if (mapActivity != null) { - boolean force = intent.getBooleanExtra(AIDL_FORCE, false); - GPXFile gpx = null; - if (intent.getStringExtra(AIDL_DATA) != null) { - String gpxStr = intent.getStringExtra(AIDL_DATA); - if (!Algorithms.isEmpty(gpxStr)) { - gpx = GPXUtilities.loadGPXFile(new ByteArrayInputStream(gpxStr.getBytes())); - } - } else if (intent.getParcelableExtra(AIDL_URI) != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - Uri gpxUri = intent.getParcelableExtra(AIDL_URI); - - ParcelFileDescriptor gpxParcelDescriptor = null; - try { - gpxParcelDescriptor = mapActivity.getContentResolver().openFileDescriptor(gpxUri, "r"); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - if (gpxParcelDescriptor != null) { - FileDescriptor fileDescriptor = gpxParcelDescriptor.getFileDescriptor(); - gpx = GPXUtilities.loadGPXFile(new FileInputStream(fileDescriptor)); - } - } - } - + GPXFile gpx = loadGpxFileFromIntent(mapActivity, intent); if (gpx != null) { - final RoutingHelper routingHelper = app.getRoutingHelper(); - if (routingHelper.isFollowingMode() && !force) { - final GPXFile gpxFile = gpx; - AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm(); - dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { + boolean force = intent.getBooleanExtra(AIDL_FORCE, false); + ExternalApiHelper.saveAndNavigateGpx(mapActivity, gpx, force); + } + } + } - @Override - public void onDismiss(DialogInterface dialog) { - MapActivity mapActivity = mapActivityRef.get(); - if (mapActivity != null && !routingHelper.isFollowingMode()) { - ExternalApiHelper.startNavigation(mapActivity, gpxFile); - } - } - }); - } else { - ExternalApiHelper.startNavigation(mapActivity, gpx); + private GPXFile loadGpxFileFromIntent(@NonNull MapActivity mapActivity, @NonNull Intent intent) { + GPXFile gpx = null; + String gpxStr = intent.getStringExtra(AIDL_DATA); + if (!Algorithms.isEmpty(gpxStr)) { + gpx = GPXUtilities.loadGPXFile(new ByteArrayInputStream(gpxStr.getBytes())); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + Uri gpxUri = intent.getParcelableExtra(AIDL_URI); + if (gpxUri != null) { + ParcelFileDescriptor gpxParcelDescriptor = null; + try { + gpxParcelDescriptor = mapActivity.getContentResolver().openFileDescriptor(gpxUri, "r"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + if (gpxParcelDescriptor != null) { + FileDescriptor fileDescriptor = gpxParcelDescriptor.getFileDescriptor(); + gpx = GPXUtilities.loadGPXFile(new FileInputStream(fileDescriptor)); } } } + return gpx; } }; registerReceiver(navigateGpxReceiver, mapActivity, AIDL_NAVIGATE_GPX); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 6cec61b52b..b3db4562d8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -30,15 +30,10 @@ import androidx.core.content.ContextCompat; import com.google.android.material.slider.Slider; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.plus.settings.backend.OsmandSettings.AutoZoomMap; -import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; -import net.osmand.plus.settings.backend.OsmandSettings.SpeedConstants; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; @@ -48,6 +43,11 @@ import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper; import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.backend.OsmandSettings.AutoZoomMap; +import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; +import net.osmand.plus.settings.backend.OsmandSettings.SpeedConstants; import net.osmand.plus.voice.CommandPlayer; import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter.GeneralRouterProfile; @@ -749,22 +749,26 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { float settingsMinSpeed = mode.getMinSpeed(); float settingsMaxSpeed = mode.getMaxSpeed(); + float settingsDefaultSpeed = mode.getDefaultSpeed(); - final int[] defaultValue = {Math.round(mode.getDefaultSpeed() * ratio[0])}; + final int[] defaultValue = {Math.round(settingsDefaultSpeed * ratio[0])}; final int[] minValue = new int[1]; final int[] maxValue = new int[1]; final int min; final int max; if (defaultSpeedOnly) { - minValue[0] = Math.round(1 * ratio[0]); - maxValue[0] = Math.round(300 * ratio[0]); + minValue[0] = Math.round(Math.min(1, settingsDefaultSpeed) * ratio[0]); + maxValue[0] = Math.round(Math.max(300, settingsDefaultSpeed) * ratio[0]); min = minValue[0]; max = maxValue[0]; } else { - minValue[0] = Math.round((settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed()) * ratio[0]); - maxValue[0] = Math.round((settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed()) * ratio[0]); - min = Math.round(router.getMinSpeed() * ratio[0] / 2f); - max = Math.round(router.getMaxSpeed() * ratio[0] * 1.5f); + float minSpeedValue = settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed(); + float maxSpeedValue = settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed(); + minValue[0] = Math.round(Math.min(minSpeedValue, settingsDefaultSpeed) * ratio[0]); + maxValue[0] = Math.round(Math.max(maxSpeedValue, settingsDefaultSpeed) * ratio[0]); + + min = Math.round(Math.min(router.getMinSpeed(), settingsDefaultSpeed) * ratio[0] / 2f); + max = Math.round(Math.max(router.getMaxSpeed(), settingsDefaultSpeed) * ratio[0] * 1.5f); } boolean nightMode = !app.getSettings().isLightContentForMode(mode); diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index 4cb07d6543..91d9a6f255 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -5,6 +5,7 @@ import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; +import android.os.AsyncTask; import android.os.Build; import android.os.ParcelFileDescriptor; @@ -15,6 +16,7 @@ import androidx.appcompat.app.AlertDialog; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.IndexConstants; @@ -26,8 +28,9 @@ import net.osmand.aidl.search.SearchParams; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmandApplication; @@ -45,6 +48,9 @@ import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.search.listitems.QuickSearchListItem; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.track.SaveGpxAsyncTask; +import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.router.TurnType; import net.osmand.search.SearchUICore; import net.osmand.search.core.ObjectType; @@ -202,7 +208,6 @@ public class ExternalApiHelper { if (API_CMD_SHOW_GPX.equals(cmd) || API_CMD_NAVIGATE_GPX.equals(cmd)) { boolean navigate = API_CMD_NAVIGATE_GPX.equals(cmd); String path = uri.getQueryParameter(PARAM_PATH); - boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false); GPXFile gpx = null; if (path != null) { @@ -240,22 +245,8 @@ public class ExternalApiHelper { if (gpx != null) { if (navigate) { - final RoutingHelper routingHelper = app.getRoutingHelper(); - if (routingHelper.isFollowingMode() && !force) { - final GPXFile gpxFile = gpx; - AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm(); - dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { - - @Override - public void onDismiss(DialogInterface dialog) { - if (!routingHelper.isFollowingMode()) { - startNavigation(mapActivity, gpxFile); - } - } - }); - } else { - startNavigation(mapActivity, gpx); - } + boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false); + saveAndNavigateGpx(mapActivity, gpx, force); } else { app.getSelectedGpxHelper().setGpxFileToDisplay(gpx); } @@ -651,6 +642,60 @@ public class ExternalApiHelper { return result; } + public static void saveAndNavigateGpx(MapActivity mapActivity, final GPXFile gpxFile, final boolean force) { + final WeakReference mapActivityRef = new WeakReference<>(mapActivity); + + if (Algorithms.isEmpty(gpxFile.path)) { + OsmandApplication app = mapActivity.getMyApplication(); + String destFileName = "route" + IndexConstants.GPX_FILE_EXT; + File destDir = app.getAppPath(IndexConstants.GPX_IMPORT_DIR); + File destFile = app.getAppPath(IndexConstants.GPX_IMPORT_DIR + destFileName); + while (destFile.exists()) { + destFileName = AndroidUtils.createNewFileName(destFileName); + destFile = new File(destDir, destFileName); + } + gpxFile.path = destFile.getAbsolutePath(); + } + + new SaveGpxAsyncTask(gpxFile, new SaveGpxListener() { + @Override + public void gpxSavingStarted() { + + } + + @Override + public void gpxSavingFinished(Exception errorMessage) { + MapActivity mapActivity = mapActivityRef.get(); + if (errorMessage == null && mapActivity != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) { + OsmandApplication app = mapActivity.getMyApplication(); + GpxSelectionHelper helper = app.getSelectedGpxHelper(); + SelectedGpxFile selectedGpx = helper.getSelectedFileByPath(gpxFile.path); + if (selectedGpx != null) { + selectedGpx.setGpxFile(gpxFile, app); + } else { + helper.selectGpxFile(gpxFile, true, false); + } + final RoutingHelper routingHelper = app.getRoutingHelper(); + if (routingHelper.isFollowingMode() && !force) { + AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm(); + dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { + + @Override + public void onDismiss(DialogInterface dialog) { + MapActivity mapActivity = mapActivityRef.get(); + if (mapActivity != null && !routingHelper.isFollowingMode()) { + ExternalApiHelper.startNavigation(mapActivity, gpxFile); + } + } + }); + } else { + startNavigation(mapActivity, gpxFile); + } + } + } + }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + private void updateTurnInfo(String prefix, Intent result, NextDirectionInfo ni) { result.putExtra(prefix + PARAM_NT_DISTANCE, ni.distanceTo); result.putExtra(prefix + PARAM_NT_IMMINENT, ni.imminent); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index 80359f7dca..8357a606fe 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -466,14 +466,16 @@ public class RoutingOptionsHelper { List list = new ArrayList(); RouteProvider.GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute(); boolean osmandRouter = am.getRouteService() == RouteProvider.RouteService.OSMAND; - if (rparams != null && !routingHelper.isCurrentGPXRouteV2() && osmandRouter) { + if (rparams != null && osmandRouter) { GPXUtilities.GPXFile fl = rparams.getFile(); if (fl.hasRtePt()) { list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates, app.getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE())); } - list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route, - app.getString(R.string.gpx_option_reverse_route), rparams.isReverse())); + if (!routingHelper.isCurrentGPXRouteV2()) { + list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route, + app.getString(R.string.gpx_option_reverse_route), rparams.isReverse())); + } if (!rparams.isUseIntermediatePointsRTE()) { list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point, app.getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute())); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index e70752b7f1..a458b281e9 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -137,7 +137,7 @@ public class RouteCalculationResult { } public RouteCalculationResult(List list, Location start, LatLon end, List intermediates, - OsmandApplication ctx, boolean leftSide, RoutingContext rctx, List waypoints, ApplicationMode mode) { + OsmandApplication ctx, boolean leftSide, RoutingContext rctx, List waypoints, ApplicationMode mode, boolean calculateFirstAndLastPoint) { if (rctx != null) { this.routingTime = rctx.routingTime; this.visitedSegments = rctx.getVisitedSegments(); @@ -162,7 +162,9 @@ public class RouteCalculationResult { List locations = new ArrayList(); ArrayList alarms = new ArrayList(); List segments = convertVectorResult(computeDirections, locations, list, alarms, ctx); - introduceFirstPointAndLastPoint(locations, computeDirections, segments, start, end, ctx); + if (calculateFirstAndLastPoint) { + introduceFirstPointAndLastPoint(locations, computeDirections, segments, start, end, ctx); + } this.locations = Collections.unmodifiableList(locations); this.segments = Collections.unmodifiableList(segments); @@ -300,6 +302,37 @@ public class RouteCalculationResult { return list; } + public List getRoute(int startIndex) { + if (segments.size() == 0) { + return null; + } + List list = new ArrayList(); + int skippedPoints = 0; + for (int i = 1; i <= startIndex; i++) { + RouteSegmentResult seg = segments.get(i - 1); + if (seg != segments.get(i)) { + skippedPoints += Math.abs(seg.getEndPointIndex() - seg.getStartPointIndex()); + } + } + list.add(segments.get(startIndex++)); + for (int i = startIndex; i < segments.size(); i++) { + if (segments.get(i - 1) != segments.get(i)) { + list.add(segments.get(i)); + } + } + if (!list.isEmpty()) { + RouteSegmentResult seg = list.get(0); + if (seg.isForwardDirection()) { + int index = seg.getStartPointIndex() + startIndex - skippedPoints; + seg.setStartPointIndex(index); + } else { + int index = seg.getEndPointIndex() + startIndex - skippedPoints; + seg.setEndPointIndex(index); + } + } + return list; + } + /** * PREPARATION */ diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 6626d5e23c..f9d43df2d2 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -79,6 +79,7 @@ public class RouteProvider { private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(RouteProvider.class); private static final String OSMAND_ROUTER = "OsmAndRouter"; private static final int MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT = 60; + private static final int ADDITIONAL_DISTANCE_FOR_START_POINT = 300; private static final int MIN_STRAIGHT_DIST = 50000; public enum RouteService { @@ -366,22 +367,51 @@ public class RouteProvider { } private RouteCalculationResult calculateGpxRoute(RouteCalculationParams routeParams) throws IOException { - - List route = routeParams.gpxRoute.route; - if (!Algorithms.isEmpty(route)) { - return new RouteCalculationResult(route, routeParams.start, routeParams.end, - routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode); - } - // get the closest point to start and to end GPXRouteParams gpxParams = routeParams.gpxRoute; + List gpxRouteResult = routeParams.gpxRoute.route; + if (!Algorithms.isEmpty(gpxRouteResult)) { + boolean calculateOsmAndRouteParts = gpxParams.calculateOsmAndRouteParts; + if (routeParams.gpxRoute.passWholeRoute && !calculateOsmAndRouteParts) { + return new RouteCalculationResult(gpxRouteResult, routeParams.start, routeParams.end, + routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode, true); + } + RouteCalculationResult result = new RouteCalculationResult(gpxRouteResult, routeParams.start, routeParams.end, + routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode, false); + List gpxRouteLocations = result.getImmutableAllLocations(); + int gpxNextIndex = routeParams.gpxRoute.passWholeRoute ? 0 : findStartIndexFromRoute(gpxRouteLocations, routeParams.start, calculateOsmAndRouteParts); + Location gpxNextLocation; + List firstSegmentRoute = null; + List gpxRoute; + if (gpxNextIndex > 0) { + gpxNextLocation = gpxRouteLocations.get(gpxNextIndex); + gpxRoute = result.getRoute(gpxNextIndex); + } else { + gpxNextLocation = gpxRouteLocations.get(0); + gpxRoute = result.getOriginalRoute(); + } + if (calculateOsmAndRouteParts + && routeParams.start != null && gpxNextLocation != null + && gpxNextLocation.distanceTo(routeParams.start) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT) { + RouteCalculationResult firstSegmentResult = findOfflineRouteSegment(routeParams, routeParams.start, new LatLon(gpxNextLocation.getLatitude(), gpxNextLocation.getLongitude())); + firstSegmentRoute = firstSegmentResult.getOriginalRoute(); + } + List newGpxRoute = new ArrayList<>(); + if (firstSegmentRoute != null && !firstSegmentRoute.isEmpty()) { + newGpxRoute.addAll(firstSegmentRoute); + } + newGpxRoute.addAll(gpxRoute); + return new RouteCalculationResult(newGpxRoute, routeParams.start, routeParams.end, + routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode, true); + } + if(routeParams.gpxRoute.useIntermediatePointsRTE){ return calculateOsmAndRouteWithIntermediatePoints(routeParams, gpxParams.points); } List gpxRoute ; int[] startI = new int[]{0}; int[] endI = new int[]{gpxParams.points.size()}; - if(routeParams.gpxRoute.passWholeRoute) { + if (routeParams.gpxRoute.passWholeRoute) { gpxRoute = gpxParams.points; if (routeParams.previousToRecalculate != null && routeParams.onlyStartPointChanged) { List routeLocations = routeParams.previousToRecalculate.getRouteLocations(); @@ -389,7 +419,7 @@ public class RouteProvider { gpxRoute = new ArrayList<>(); Location trackStart = routeLocations.get(0); Location realStart = routeParams.start; - //insert route segment from current location to next route location if user deviated from route + //insert gpxRouteResult segment from current location to next gpxRouteResult location if user deviated from gpxRouteResult if (realStart != null && trackStart != null && realStart.distanceTo(trackStart) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT && !gpxParams.calculateOsmAndRouteParts) { @@ -625,6 +655,30 @@ public class RouteProvider { return sublist; } + private int findStartIndexFromRoute(List route, Location startLoc, boolean calculateOsmAndRouteParts) { + float minDist = Integer.MAX_VALUE; + int start = 0; + if (startLoc != null) { + for (int i = 0; i < route.size(); i++) { + float d = route.get(i).distanceTo(startLoc); + if (d < minDist) { + start = i; + minDist = d; + } + } + } + if (start > 0 && calculateOsmAndRouteParts) { + Location newStartLoc = route.get(start); + for (int i = start + 1; i < route.size(); i++) { + Location loc = route.get(i); + if (loc.distanceTo(newStartLoc) >= ADDITIONAL_DISTANCE_FOR_START_POINT) { + return i; + } + } + } + return start; + } + protected String getString(Context ctx, int resId){ if(ctx == null){ return ""; //$NON-NLS-1$ @@ -812,7 +866,7 @@ public class RouteProvider { } else { RouteCalculationResult res = new RouteCalculationResult(result, params.start, params.end, params.intermediates, params.ctx, params.leftSide, ctx, params.gpxRoute == null? null: params.gpxRoute.wpt, - params.mode); + params.mode, true); return res; } } catch (RuntimeException e) {