private void showOnMap(LatLon latLon, boolean updateCoords, boolean ignoreCoef) {
    AnimateDraggingMapThread thread = map.getAnimatedDraggingThread();
    int fZoom = map.getZoom();
    double flat = latLon.getLatitude();
    double flon = latLon.getLongitude();

    RotatedTileBox cp = map.getCurrentRotatedTileBox().copy();
    if (ignoreCoef) {
      cp.setCenterLocation(0.5f, 0.5f);
    } else {
      cp.setCenterLocation(
          0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
    }
    cp.setLatLonCenter(flat, flon);
    flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
    flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);

    if (updateCoords) {
      mapCenter = new LatLon(flat, flon);
      menu.setMapCenter(mapCenter);
      origMarkerX = cp.getCenterPixelX();
      origMarkerY = cp.getCenterPixelY();
    }

    thread.startMoving(flat, flon, fZoom, true);
  }
 @Override
 public void onDestroyView() {
   super.onDestroyView();
   map.setLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
   menu.setMapCenter(null);
   getMapActivity().getMapLayers().getMapControlsLayer().setControlsClickable(true);
 }
  public void moveTo(float dx, float dy) {
    final QuadPoint cp = currentViewport.getCenterPixelPoint();
    final LatLon latlon = currentViewport.getLatLonFromPixel(cp.x + dx, cp.y + dy);
    currentViewport.setLatLonCenter(latlon.getLatitude(), latlon.getLongitude());
    refreshMap();
    // do not notify here listener

  }
 protected void click(final OsmandMapTileView view) {
   AnimateDraggingMapThread thread = view.getAnimatedDraggingThread();
   LatLon pointToNavigate = getPointToNavigate();
   if (pointToNavigate != null) {
     int fZoom = view.getZoom() < 15 ? 15 : view.getZoom();
     thread.startMoving(
         pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true);
   }
 }
Example #5
0
 @Override
 public void locationUpdate(LatLon loc) {
   if (view != null) {
     if (loc != null) {
       updateUI(loc.getLatitude(), loc.getLongitude());
     } else {
       updateUI(0, 0);
     }
   }
 }
 @Override
 public void onDestroyView() {
   super.onDestroyView();
   if (mapCenter != null) {
     PointI centerI =
         Utilities.convertLatLonTo31(
             new net.osmand.core.jni.LatLon(mapCenter.getLatitude(), mapCenter.getLongitude()));
     getMainActivity().setTarget(centerI);
   }
   menu.setMapCenter(null);
   menu.setMapZoom(0);
 }
 public int getDistance() {
   int d = 0;
   LatLon l = getPointToNavigate();
   if (l != null) {
     Location.distanceBetween(
         view.getLatitude(),
         view.getLongitude(),
         l.getLatitude(),
         l.getLongitude(),
         calculations);
     d = (int) calculations[0];
   }
   return d;
 }
  public void searchTransport() {
    // use progress
    stopsAdapter.clear();
    searchArea.setText(getSearchArea());
    boolean routeCalculated = isRouteCalculated();
    searchTransportLevel.setEnabled(false);
    if (!routeCalculated && getLocationToStart() != null) {
      final LatLon locationToStart = getLocationToStart();
      final LatLon locationToGo = getLocationToGo();
      List<TransportIndexRepository> rs =
          ((OsmandApplication) getApplication())
              .getResourceManager()
              .searchTransportRepositories(
                  locationToStart.getLatitude(), locationToStart.getLongitude());
      if (!rs.isEmpty()) {
        repo = rs.get(0);
        progress.setVisibility(View.VISIBLE);
        synchronized (this) {
          final Thread previousThread = thread;
          thread =
              new Thread(
                  new Runnable() {
                    @Override
                    public void run() {
                      if (previousThread != null) {
                        try {
                          previousThread.join();
                        } catch (InterruptedException e) {
                        }
                      }
                      List<RouteInfoLocation> res =
                          repo.searchTransportRouteStops(
                              locationToStart.getLatitude(),
                              locationToStart.getLongitude(),
                              locationToGo,
                              zoom);
                      updateUIList(res);
                    }
                  },
                  "SearchingTransport"); //$NON-NLS-1$
          thread.start();
        }

      } else {
        repo = null;
      }
    } else {
      updateSearchMoreButton();
    }
  }
 public void setFragmentVisibility(boolean visible) {
   if (visible) {
     view.setVisibility(View.VISIBLE);
     if (mapCenter != null) {
       PointI targetI =
           Utilities.convertLatLonTo31(
               new net.osmand.core.jni.LatLon(mapCenter.getLatitude(), mapCenter.getLongitude()));
       getMainActivity().setTarget(targetI);
     }
     adjustMapPosition(getPosY(), true, false);
   } else {
     view.setVisibility(View.GONE);
   }
 }
Example #10
0
 @Override
 public boolean onTrackballEvent(MotionEvent event) {
   if (event.getAction() == MotionEvent.ACTION_MOVE
       && settings.USE_TRACKBALL_FOR_MOVEMENTS.get()) {
     float x = event.getX();
     float y = event.getY();
     LatLon l =
         mapView.getLatLonFromScreenPoint(
             mapView.getCenterPointX() + x * 15, mapView.getCenterPointY() + y * 15);
     setMapLocation(l.getLatitude(), l.getLongitude());
     return true;
   }
   return super.onTrackballEvent(event);
 }
Example #11
0
    private void changeZoomPosition(float dz, float angle) {
      final QuadPoint cp = initialViewport.getCenterPixelPoint();
      float dx = cp.x - initialMultiTouchCenterPoint.x;
      float dy = cp.y - initialMultiTouchCenterPoint.y;
      final RotatedTileBox calc = initialViewport.copy();
      calc.setLatLonCenter(initialCenterLatLon.getLatitude(), initialCenterLatLon.getLongitude());

      float calcZoom = initialViewport.getZoom() + dz + initialViewport.getZoomScale();
      float calcRotate = calc.getRotate() + angle;
      calc.setRotate(calcRotate);
      calc.setZoomAnimation(dz);
      final LatLon r = calc.getLatLonFromPixel(cp.x + dx, cp.y + dy);
      setLatLon(r.getLatitude(), r.getLongitude());
      zoomToAnimate(calcZoom, true);
      rotateToAnimate(calcRotate);
    }
Example #12
0
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER && app.getInternalAPI().accessibilityEnabled()) {
     if (!uiHandler.hasMessages(LONG_KEYPRESS_MSG_ID)) {
       Message msg =
           Message.obtain(
               uiHandler,
               new Runnable() {
                 @Override
                 public void run() {
                   app.getLocationProvider().emitNavigationHint();
                 }
               });
       msg.what = LONG_KEYPRESS_MSG_ID;
       uiHandler.sendMessageDelayed(msg, LONG_KEYPRESS_DELAY);
     }
     return true;
   } else if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0) {
     mapActions.openOptionsMenuAsList();
     return true;
   } else if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
     Intent newIntent = new Intent(MapActivity.this, OsmandIntents.getSearchActivity());
     // causes wrong position caching:  newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
     LatLon loc = getMapLocation();
     newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude());
     newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude());
     startActivity(newIntent);
     newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     return true;
   } else if (!app.getRoutingHelper().isFollowingMode()
       && OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) != null) {
     // Find more appropriate plugin for it?
     if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && event.getRepeatCount() == 0) {
       if (mapView.isZooming()) {
         changeZoom(mapView.getZoom() + 2);
       } else {
         changeZoom(mapView.getZoom() + 1);
       }
       return true;
     } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && event.getRepeatCount() == 0) {
       changeZoom(mapView.getZoom() - 1);
       return true;
     }
   }
   return super.onKeyDown(keyCode, event);
 }
 protected void select(int mode) {
   LatLon searchPoint = settings.getLastSearchedPoint();
   AddressInformation ai = getAddressInformation();
   if (ai != null) {
     if (mode == ADD_TO_FAVORITE) {
       Bundle b = new Bundle();
       Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(getActivity(), b);
       dlg.show();
       FavoriteDialogs.prepareAddFavouriteDialog(
           getActivity(),
           dlg,
           b,
           searchPoint.getLatitude(),
           searchPoint.getLongitude(),
           new PointDescription(PointDescription.POINT_TYPE_ADDRESS, ai.objectName));
     } else if (mode == NAVIGATE_TO) {
       DirectionsDialogs.directionsToDialogAndLaunchMap(
           getActivity(),
           searchPoint.getLatitude(),
           searchPoint.getLongitude(),
           ai.getHistoryName());
     } else if (mode == ADD_WAYPOINT) {
       DirectionsDialogs.addWaypointDialogAndLaunchMap(
           getActivity(),
           searchPoint.getLatitude(),
           searchPoint.getLongitude(),
           ai.getHistoryName());
     } else if (mode == SHOW_ON_MAP) {
       showOnMap(searchPoint, ai);
     }
   }
 }
Example #14
0
 @Override
 public boolean onKeyUp(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
     if (!app.getInternalAPI().accessibilityEnabled()) {
       mapActions.contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
     } else if (uiHandler.hasMessages(LONG_KEYPRESS_MSG_ID)) {
       uiHandler.removeMessages(LONG_KEYPRESS_MSG_ID);
       mapActions.contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
     }
     return true;
   } else if (settings.ZOOM_BY_TRACKBALL.get()) {
     // Parrot device has only dpad left and right
     if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
       changeZoom(mapView.getZoom() - 1);
       return true;
     } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
       changeZoom(mapView.getZoom() + 1);
       return true;
     }
   } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT
       || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT
       || keyCode == KeyEvent.KEYCODE_DPAD_DOWN
       || keyCode == KeyEvent.KEYCODE_DPAD_UP) {
     int dx =
         keyCode == KeyEvent.KEYCODE_DPAD_RIGHT
             ? 15
             : (keyCode == KeyEvent.KEYCODE_DPAD_LEFT ? -15 : 0);
     int dy =
         keyCode == KeyEvent.KEYCODE_DPAD_DOWN
             ? 15
             : (keyCode == KeyEvent.KEYCODE_DPAD_UP ? -15 : 0);
     LatLon l =
         mapView.getLatLonFromScreenPoint(
             mapView.getCenterPointX() + dx, mapView.getCenterPointY() + dy);
     setMapLocation(l.getLatitude(), l.getLongitude());
     return true;
   } else if (OsmandPlugin.onMapActivityKeyUp(this, keyCode)) {
     return true;
   }
   return super.onKeyUp(keyCode, event);
 }
Example #15
0
 @Override
 public void onZoomEnded(double relativeToStart, float angleRelative) {
   // 1.5 works better even on dm.density=1 devices
   float dz = (float) (Math.log(relativeToStart) / Math.log(2)) * 1.5f;
   setIntZoom(Math.round(dz) + initialViewport.getZoom());
   if (Math.abs(angleRelative) < ANGLE_THRESHOLD) {
     angleRelative = 0;
   }
   rotateToAnimate(initialViewport.getRotate() + angleRelative);
   final int newZoom = getZoom();
   if (application.getInternalAPI().accessibilityEnabled()) {
     if (newZoom != initialViewport.getZoom()) {
       showMessage(getContext().getString(R.string.zoomIs) + " " + newZoom); // $NON-NLS-1$
     } else {
       final LatLon p1 = initialViewport.getLatLonFromPixel(x1, y1);
       final LatLon p2 = initialViewport.getLatLonFromPixel(x2, y2);
       showMessage(
           OsmAndFormatter.getFormattedDistance(
               (float)
                   MapUtils.getDistance(
                       p1.getLatitude(), p1.getLongitude(), p2.getLatitude(), p2.getLongitude()),
               application));
     }
   }
 }
  private void adjustMapPosition(int y, boolean animated) {
    double markerLat = menu.getLatLon().getLatitude();
    double markerLon = menu.getLatLon().getLongitude();
    RotatedTileBox box = map.getCurrentRotatedTileBox().copy();

    LatLon latlon = mapCenter;
    if (menu.isLandscapeLayout()) {
      int markerX = (int) box.getPixXFromLatLon(markerLat, markerLon);
      int x = dpToPx(menu.getLandscapeWidthDp());
      if (markerX - markerPaddingXPx < x || markerX > origMarkerX) {
        int dx = (x + markerPaddingXPx) - markerX;
        if (markerX - dx <= origMarkerX) {
          QuadPoint cp = box.getCenterPixelPoint();
          latlon = box.getLatLonFromPixel(cp.x - dx, cp.y);
        } else {
          latlon = box.getCenterLatLon();
        }
      }
    } else {
      int markerY = (int) box.getPixYFromLatLon(markerLat, markerLon);
      if (markerY + markerPaddingPx > y || markerY < origMarkerY) {
        int dy = markerY - (y - markerPaddingPx);
        if (markerY - dy <= origMarkerY) {
          QuadPoint cp = box.getCenterPixelPoint();
          latlon = box.getLatLonFromPixel(cp.x + 0, cp.y + dy);
        }
      }
    }

    if (map.getLatitude() == latlon.getLatitude() && map.getLongitude() == latlon.getLongitude()) {
      return;
    }

    if (animated) {
      showOnMap(latlon, false, true);
    } else {
      map.setLatLon(latlon.getLatitude(), latlon.getLongitude());
    }
  }
Example #17
0
  public View onCreateView(
      android.view.LayoutInflater inflater,
      android.view.ViewGroup container,
      Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.navigate_point, container, false);
    setHasOptionsMenu(true);

    LatLon loc = null;
    OsmandApplication app = (OsmandApplication) getActivity().getApplication();
    Intent intent = getSherlockActivity().getIntent();
    if (intent != null) {
      double lat = intent.getDoubleExtra(SEARCH_LAT, 0);
      double lon = intent.getDoubleExtra(SEARCH_LON, 0);
      if (lat != 0 || lon != 0) {
        loc = new LatLon(lat, lon);
      }
    }
    if (loc == null && getActivity() instanceof SearchActivity) {
      loc = ((SearchActivity) getActivity()).getSearchPoint();
    }
    if (loc == null) {
      loc = app.getSettings().getLastKnownMapLocation();
    }
    initUI(loc.getLatitude(), loc.getLongitude());
    if (savedInstanceState != null
        && savedInstanceState.containsKey(SEARCH_LAT)
        && savedInstanceState.containsKey(SEARCH_LON)) {
      String lat = savedInstanceState.getString(SEARCH_LAT);
      String lon = savedInstanceState.getString(SEARCH_LON);
      if (lat != null && lon != null && lat.length() > 0 && lon.length() > 0) {
        ((Spinner) view.findViewById(R.id.Format))
            .setSelection(savedInstanceState.getInt(SELECTION, 0));
        currentFormat = savedInstanceState.getInt(SELECTION, 0);
        ((TextView) view.findViewById(R.id.LatitudeEdit)).setText(lat);
        ((TextView) view.findViewById(R.id.LongitudeEdit)).setText(lon);
      }
    }
    return view;
  };
Example #18
0
 private void filterPOI() {
   Bundle extras = getIntent().getExtras();
   boolean searchNearBy = true;
   LatLon lastKnownMapLocation =
       ((OsmandApplication) getApplication()).getSettings().getLastKnownMapLocation();
   double latitude = lastKnownMapLocation != null ? lastKnownMapLocation.getLatitude() : 0;
   double longitude = lastKnownMapLocation != null ? lastKnownMapLocation.getLongitude() : 0;
   final Intent newIntent = new Intent(EditPOIFilterActivity.this, SearchPOIActivity.class);
   if (extras != null && extras.containsKey(SEARCH_LAT) && extras.containsKey(SEARCH_LON)) {
     latitude = extras.getDouble(SEARCH_LAT);
     longitude = extras.getDouble(SEARCH_LON);
     searchNearBy = false;
   }
   final double lat = latitude;
   final double lon = longitude;
   newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
   if (searchNearBy) {
     AlertDialog.Builder b = new AlertDialog.Builder(EditPOIFilterActivity.this);
     b.setItems(
         new String[] {getString(R.string.search_nearby), getString(R.string.search_near_map)},
         new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
             if (which == 1) {
               newIntent.putExtra(SearchPOIActivity.SEARCH_LAT, lat);
               newIntent.putExtra(SearchPOIActivity.SEARCH_LON, lon);
             }
             startActivity(newIntent);
           }
         });
     b.show();
   } else {
     newIntent.putExtra(SearchPOIActivity.SEARCH_LAT, lat);
     newIntent.putExtra(SearchPOIActivity.SEARCH_LON, lon);
     startActivity(newIntent);
   }
 }
  private void showOnMap(
      LatLon latLon, boolean updateCoords, boolean needMove, boolean alreadyAdjusted) {
    // AnimateDraggingMapThread thread = map.getAnimatedDraggingThread(); todo amimation
    int fZoom = getZoom();
    double flat = latLon.getLatitude();
    double flon = latLon.getLongitude();

    RotatedTileBox cp = getBox();
    // cp.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f :
    // 0.5f);
    cp.setLatLonCenter(flat, flon);
    cp.setZoom(fZoom);
    flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
    flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);

    if (updateCoords) {
      mapCenter = new LatLon(flat, flon);
      menu.setMapCenter(mapCenter);
      origMarkerX = cp.getCenterPixelX();
      origMarkerY = cp.getCenterPixelY();
    }

    if (!alreadyAdjusted) {
      LatLon adjustedLatLon =
          getAdjustedMarkerLocation(getPosY(), new LatLon(flat, flon), true, fZoom);
      flat = adjustedLatLon.getLatitude();
      flon = adjustedLatLon.getLongitude();
    }

    if (needMove) {
      // thread.startMoving(flat, flon, fZoom, true); todo animation
      PointI targetI = Utilities.convertLatLonTo31(new net.osmand.core.jni.LatLon(flat, flon));
      getMainActivity().setTarget(targetI);
      getMainActivity().setZoom(fZoom);
    }
  }
  private void adjustMapPosition(int y, boolean animated, boolean center) {
    // map.getAnimatedDraggingThread().stopAnimatingSync(); todo animation
    LatLon latlon = getAdjustedMarkerLocation(y, menu.getLatLon(), center, getZoom());

    LatLon mapLatLon = getMainActivity().getScreenCenter();
    if (mapLatLon.getLatitude() == latlon.getLatitude()
        && mapLatLon.getLongitude() == latlon.getLongitude()) {
      return;
    }

    if (animated) {
      showOnMap(latlon, false, true, true);
    } else {
      PointI targetI =
          Utilities.convertLatLonTo31(
              new net.osmand.core.jni.LatLon(latlon.getLatitude(), latlon.getLongitude()));
      getMainActivity().setTarget(targetI);
    }
  }
Example #21
0
  @Override
  protected void onResume() {
    super.onResume();
    cancelNotification();
    if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
      setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get());
      // can't return from this method we are not sure if activity will be recreated or not
    }

    app.getLocationProvider().checkIfLastKnownLocationIsValid();
    // for voice navigation
    if (settings.AUDIO_STREAM_GUIDANCE.get() != null) {
      setVolumeControlStream(settings.AUDIO_STREAM_GUIDANCE.get());
    } else {
      setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }

    applicationModeListener =
        new StateChangedListener<ApplicationMode>() {
          @Override
          public void stateChanged(ApplicationMode change) {
            updateApplicationModeSettings();
          }
        };
    settings.APPLICATION_MODE.addListener(applicationModeListener);
    updateApplicationModeSettings();

    String filterId = settings.getPoiFilterForMap();
    PoiFilter poiFilter = app.getPoiFilters().getFilterById(filterId);
    if (poiFilter == null) {
      poiFilter = new PoiFilter(null, app);
    }

    mapLayers.getPoiMapLayer().setFilter(poiFilter);

    // if destination point was changed try to recalculate route
    TargetPointsHelper targets = app.getTargetPointsHelper();
    RoutingHelper routingHelper = app.getRoutingHelper();
    if (routingHelper.isFollowingMode()
        && (!Algorithms.objectEquals(targets.getPointToNavigate(), routingHelper.getFinalLocation())
            || !Algorithms.objectEquals(
                targets.getIntermediatePoints(), routingHelper.getIntermediatePoints()))) {
      routingHelper.setFinalAndCurrentLocation(
          targets.getPointToNavigate(),
          targets.getIntermediatePoints(),
          app.getLocationProvider().getLastKnownLocation(),
          routingHelper.getCurrentGPXRoute());
    }
    app.getLocationProvider().resumeAllUpdates();

    if (settings != null && settings.isLastKnownMapLocation()) {
      LatLon l = settings.getLastKnownMapLocation();
      mapView.setLatLon(l.getLatitude(), l.getLongitude());
      mapView.setZoom(settings.getLastKnownMapZoom());
    }

    settings.MAP_ACTIVITY_ENABLED.set(true);
    checkExternalStorage();
    showAndHideMapPosition();

    LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude());
    LatLon latLonToShow = settings.getAndClearMapLocationToShow();
    String mapLabelToShow = settings.getAndClearMapLabelToShow();
    Object toShow = settings.getAndClearObjectToShow();
    if (settings.isRouteToPointNavigateAndClear()) {
      // always enable and follow and let calculate it (GPS is not accessible in garage)
      mapActions.getDirections(null, null, false);
    }
    if (mapLabelToShow != null && latLonToShow != null) {
      mapLayers.getContextMenuLayer().setSelectedObject(toShow);
      mapLayers.getContextMenuLayer().setLocation(latLonToShow, mapLabelToShow);
    }
    if (latLonToShow != null && !latLonToShow.equals(cur)) {
      mapView
          .getAnimatedDraggingThread()
          .startMoving(
              latLonToShow.getLatitude(),
              latLonToShow.getLongitude(),
              settings.getMapZoomToShow(),
              true);
    }
    if (latLonToShow != null) {
      // remember if map should come back to isMapLinkedToLocation=true
      mapViewTrackingUtilities.setMapLinkedToLocation(false);
    }

    View progress = mapLayers.getMapInfoLayer().getProgressBar();
    if (progress != null) {
      app.getResourceManager().setBusyIndicator(new BusyIndicator(this, progress));
    }

    OsmandPlugin.onMapActivityResume(this);
    mapView.refreshMap(true);
  }
Example #22
0
  private Location setCurrentLocation(
      Location currentLocation,
      boolean returnUpdatedLocation,
      RouteCalculationResult previousRoute) {
    Location locationProjection = currentLocation;
    if (finalLocation == null || currentLocation == null) {
      makeUturnWhenPossible = false;
      return locationProjection;
    }
    float posTolerance = POSITION_TOLERANCE;
    if (currentLocation.hasAccuracy()) {
      posTolerance = POSITION_TOLERANCE / 2 + currentLocation.getAccuracy();
    }
    boolean calculateRoute = false;
    synchronized (this) {
      // 0. Route empty or needs to be extended? Then re-calculate route.
      if (route.isEmpty()) {
        calculateRoute = true;
      } else {
        // 1. Update current route position status according to latest received location
        boolean finished = updateCurrentRouteStatus(currentLocation, posTolerance);
        if (finished) {
          return null;
        }
        List<Location> routeNodes = route.getImmutableAllLocations();
        int currentRoute = route.currentRoute;

        // 2. Analyze if we need to recalculate route
        // >100m off current route (sideways)
        if (currentRoute > 0) {
          double dist =
              getOrthogonalDistance(
                  currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
          if (dist > 1.7 * posTolerance) {
            log.info("Recalculate route, because correlation  : " + dist); // $NON-NLS-1$
            calculateRoute = true;
          }
          if (dist > 350) {
            voiceRouter.announceOffRoute(dist);
          }
        }
        // 3. Identify wrong movement direction
        Location next = route.getNextRouteLocation();
        boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next);
        if (wrongMovementDirection
            && currentLocation.distanceTo(routeNodes.get(currentRoute)) > 2 * posTolerance) {
          log.info(
              "Recalculate route, because wrong movement direction: "
                  + currentLocation.distanceTo(routeNodes.get(currentRoute))); // $NON-NLS-1$
          calculateRoute = true;
        }
        // 4. Identify if UTurn is needed
        boolean uTurnIsNeeded = identifyUTurnIsNeeded(currentLocation, posTolerance);
        // 5. Update Voice router
        if (isFollowingMode) {
          // don't update in route planing mode
          announceGpxWaypoints(currentLocation);
          boolean inRecalc = calculateRoute || isRouteBeingCalculated();
          if (!inRecalc && !uTurnIsNeeded && !wrongMovementDirection) {
            voiceRouter.updateStatus(currentLocation, false);
          } else if (uTurnIsNeeded) {
            voiceRouter.makeUTStatus();
          }
        }

        // calculate projection of current location
        if (currentRoute > 0) {
          locationProjection = new Location(currentLocation);
          Location nextLocation = routeNodes.get(currentRoute);
          LatLon project =
              getProject(
                  currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));

          locationProjection.setLatitude(project.getLatitude());
          locationProjection.setLongitude(project.getLongitude());
          // we need to update bearing too
          float bearingTo = locationProjection.bearingTo(nextLocation);
          locationProjection.setBearing(bearingTo);
        }
      }
      lastFixedLocation = currentLocation;
      lastProjection = locationProjection;
    }

    if (calculateRoute) {
      recalculateRouteInBackground(
          false,
          currentLocation,
          finalLocation,
          intermediatePoints,
          currentGPXRoute,
          previousRoute.isCalculated() ? previousRoute : null);
    } else if (currentRunningJob != null && currentRunningJob instanceof RouteRecalculationThread) {
      RouteRecalculationThread thread = (RouteRecalculationThread) currentRunningJob;
      thread.stopCalculation();
    }

    double projectDist = mode != null && mode.hasFastSpeed() ? posTolerance : posTolerance / 2;
    if (returnUpdatedLocation
        && locationProjection != null
        && currentLocation.distanceTo(locationProjection) < projectDist) {
      return locationProjection;
    } else {
      return currentLocation;
    }
  }
 public void showOnMap(LatLon searchPoint, AddressInformation ai) {
   settings.setMapLocationToShow(
       searchPoint.getLatitude(), searchPoint.getLongitude(), ai.zoom, ai.getHistoryName());
   MapActivity.launchMapActivityMoveToTop(getActivity());
 }
  private LatLon getAdjustedMarkerLocation(
      int y, LatLon reqMarkerLocation, boolean center, int zoom) {
    double markerLat = reqMarkerLocation.getLatitude();
    double markerLon = reqMarkerLocation.getLongitude();
    RotatedTileBox box = getBox();
    // box.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f :
    // 0.5f);
    box.setZoom(zoom);
    int markerMapCenterX =
        (int) box.getPixXFromLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
    int markerMapCenterY =
        (int) box.getPixYFromLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
    float cpyOrig = box.getCenterPixelPoint().y;

    box.setCenterLocation(0.5f, 0.5f);
    int markerX = (int) box.getPixXFromLatLon(markerLat, markerLon);
    int markerY = (int) box.getPixYFromLatLon(markerLat, markerLon);
    QuadPoint cp = box.getCenterPixelPoint();
    float cpx = cp.x;
    float cpy = cp.y;

    float cpyDelta = menu.isLandscapeLayout() ? 0 : cpyOrig - cpy;

    markerY += cpyDelta;
    y += cpyDelta;
    float origMarkerY = this.origMarkerY + cpyDelta;

    LatLon latlon;
    if (center) {
      latlon = reqMarkerLocation;
    } else {
      latlon = box.getLatLonFromPixel(markerMapCenterX, markerMapCenterY);
    }
    if (menu.isLandscapeLayout()) {
      int x = menu.getLandscapeWidthPx();
      if (markerX - markerPaddingXPx < x || markerX > origMarkerX) {
        int dx = (x + markerPaddingXPx) - markerX;
        int dy = 0;
        if (center) {
          dy = (int) cpy - markerY;
        } else {
          cpy = cpyOrig;
        }
        if (dx >= 0 || center) {
          latlon = box.getLatLonFromPixel(cpx - dx, cpy - dy);
        }
      }
    } else {
      if (markerY + markerPaddingPx > y || markerY < origMarkerY) {
        int dx = 0;
        int dy = markerY - (y - markerPaddingPx);
        if (markerY - dy <= origMarkerY) {
          if (center) {
            dx = markerX - (int) cpx;
          }
          latlon = box.getLatLonFromPixel(cpx + dx, cpy + dy);
        }
      }
    }
    return latlon;
  }