Search in sources :

Example 6 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class QuickSearchListAdapter method updateCompassVisibility.

private void updateCompassVisibility(View view, QuickSearchListItem listItem) {
    View compassView = view.findViewById(R.id.compass_layout);
    Location ll = app.getLocationProvider().getLastKnownLocation();
    boolean showCompass = location != null && listItem.getSearchResult().location != null;
    if ((ll != null || useMapCenter) && showCompass) {
        updateDistanceDirection(view, listItem);
        compassView.setVisibility(View.VISIBLE);
    } else {
        if (!showCompass) {
            compassView.setVisibility(View.GONE);
        } else {
            compassView.setVisibility(View.INVISIBLE);
        }
    }
}
Also used : ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Location(net.osmand.Location)

Example 7 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RouteCalculationResult method getDistanceToFinish.

public int getDistanceToFinish(Location fromLoc) {
    if (listDistance != null && currentRoute < listDistance.length) {
        int dist = listDistance[currentRoute];
        Location l = locations.get(currentRoute);
        if (fromLoc != null) {
            dist += fromLoc.distanceTo(l);
        }
        return dist;
    }
    return 0;
}
Also used : LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location)

Example 8 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RouteCalculationResult method introduceFirstPointAndLastPoint.

/**
 * PREPARATION
 * If beginning is too far from start point, then introduce GO Ahead
 * @param end
 */
private static void introduceFirstPointAndLastPoint(List<Location> locations, List<RouteDirectionInfo> directions, List<RouteSegmentResult> segs, Location start, LatLon end) {
    if (!locations.isEmpty() && locations.get(0).distanceTo(start) > 50) {
        // add start point
        locations.add(0, start);
        if (segs != null) {
            segs.add(0, segs.get(0));
        }
        if (directions != null && !directions.isEmpty()) {
            for (RouteDirectionInfo i : directions) {
                i.routePointOffset++;
            }
            RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(), TurnType.straight());
            info.routePointOffset = 0;
            // info.setDescriptionRoute(ctx.getString( R.string.route_head));//; //$NON-NLS-1$
            directions.add(0, info);
        }
        checkForDuplicatePoints(locations, directions);
    }
    RouteDirectionInfo lastDirInf = directions.size() > 0 ? directions.get(directions.size() - 1) : null;
    if ((lastDirInf == null || lastDirInf.routePointOffset < locations.size() - 1) && locations.size() - 1 > 0) {
        int type = TurnType.C;
        Location prevLast = locations.get(locations.size() - 2);
        float lastBearing = prevLast.bearingTo(locations.get(locations.size() - 1));
        float[] compute = new float[2];
        Location.distanceBetween(prevLast.getLatitude(), prevLast.getLongitude(), end.getLatitude(), end.getLongitude(), compute);
        float bearingToEnd = compute[1];
        double diff = MapUtils.degreesDiff(lastBearing, bearingToEnd);
        if (Math.abs(diff) > 10) {
            type = diff > 0 ? TurnType.KL : TurnType.KR;
        }
        // Wrong AvgSpeed for the last turn can cause significantly wrong total travel time if calculated route ends on a GPX route segment (then last turn is where GPX is joined again)
        RouteDirectionInfo info = new RouteDirectionInfo(lastDirInf != null ? lastDirInf.getAverageSpeed() : 1, TurnType.valueOf(type, false));
        info.distance = 0;
        info.afterLeftTime = 0;
        info.routePointOffset = locations.size() - 1;
        directions.add(info);
    }
}
Also used : LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location)

Example 9 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RouteCalculationResult method getLeftTime.

public int getLeftTime(Location fromLoc) {
    int time = 0;
    if (currentDirectionInfo < directions.size()) {
        RouteDirectionInfo current = directions.get(currentDirectionInfo);
        time = current.afterLeftTime;
        int distanceToNextTurn = listDistance[currentRoute];
        if (currentDirectionInfo + 1 < directions.size()) {
            distanceToNextTurn -= listDistance[directions.get(currentDirectionInfo + 1).routePointOffset];
        }
        Location l = locations.get(currentRoute);
        if (fromLoc != null) {
            distanceToNextTurn += fromLoc.distanceTo(l);
        }
        time += distanceToNextTurn / current.getAverageSpeed();
    }
    return time;
}
Also used : LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location)

Example 10 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RouteProvider method findOSRMRoute.

protected RouteCalculationResult findOSRMRoute(RouteCalculationParams params) throws MalformedURLException, IOException, JSONException {
    // http://router.project-osrm.org/route/v1/driving/4.83,52.28;4.95,52.28
    List<Location> res = new ArrayList<Location>();
    StringBuilder uri = new StringBuilder();
    // possibly hide that API key because it is privacy of osmand
    // A6421860EBB04234AB5EF2D049F2CD8F key is compromised
    String scheme = "";
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        scheme = "https";
    } else {
        scheme = "http";
    }
    // $NON-NLS-1$
    uri.append(scheme + "://router.project-osrm.org/route/v1/driving/");
    uri.append(String.valueOf(params.start.getLongitude()));
    uri.append(",").append(String.valueOf(params.start.getLatitude()));
    if (params.intermediates != null && params.intermediates.size() > 0) {
        for (LatLon il : params.intermediates) {
            appendOSRMLoc(uri, il);
        }
    }
    appendOSRMLoc(uri, params.end);
    // to get more waypoints, add overview=full option
    // uri.append("?overview=full")
    log.info("URL route " + uri);
    URLConnection connection = NetworkUtils.getHttpURLConnection(uri.toString());
    connection.setRequestProperty("User-Agent", Version.getFullVersion(params.ctx));
    StringBuilder content = new StringBuilder();
    BufferedReader rs = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String s;
    while ((s = rs.readLine()) != null) {
        content.append(s);
    }
    JSONObject obj = new JSONObject(content.toString());
    try {
        rs.close();
    } catch (IOException e) {
    }
    List<LatLon> route = GeoPolylineParserUtil.parse(obj.getJSONArray("routes").getJSONObject(0).getString("geometry"), GeoPolylineParserUtil.PRECISION_5);
    if (route.isEmpty()) {
        return new RouteCalculationResult("Route is empty");
    }
    for (LatLon pt : route) {
        WptPt wpt = new WptPt();
        wpt.lat = pt.getLatitude();
        wpt.lon = pt.getLongitude();
        res.add(createLocation(wpt));
    }
    params.intermediates = null;
    return new RouteCalculationResult(res, null, params, null, true);
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URLConnection(java.net.URLConnection) LatLon(net.osmand.data.LatLon) JSONObject(org.json.JSONObject) BufferedReader(java.io.BufferedReader) Location(net.osmand.Location)

Aggregations

Location (net.osmand.Location)105 LatLon (net.osmand.data.LatLon)37 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)29 ArrayList (java.util.ArrayList)21 LocationPoint (net.osmand.data.LocationPoint)21 View (android.view.View)13 OsmandApplication (net.osmand.plus.OsmandApplication)12 Paint (android.graphics.Paint)11 TextView (android.widget.TextView)11 ImageView (android.widget.ImageView)10 RouteDataObject (net.osmand.binary.RouteDataObject)9 WptPt (net.osmand.plus.GPXUtilities.WptPt)9 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)7 PointDescription (net.osmand.data.PointDescription)6 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 IOException (java.io.IOException)5 QuadPoint (net.osmand.data.QuadPoint)5 MapActivity (net.osmand.plus.activities.MapActivity)5