Search in sources :

Example 6 with Instruction

use of com.graphhopper.util.Instruction in project PocketMaps by junjunguo.

the class Navigator method toString.

public String toString() {
    StringBuilder sb = new StringBuilder();
    if (ghResponse.getInstructions() != null) {
        for (Instruction i : ghResponse.getInstructions()) {
            sb.append("------>\ntime <long>: " + i.getTime());
            sb.append("\n");
            sb.append("name: street name" + i.getName());
            sb.append("\n");
            sb.append("annotation <InstructionAnnotation>");
            sb.append(i.getAnnotation().toString());
            sb.append("\n");
            sb.append("distance");
            sb.append(i.getDistance() + "\n");
            sb.append("sign <int>:" + i.getSign());
            sb.append("\n");
            sb.append("Points <PointsList>: " + i.getPoints());
            sb.append("\n");
        }
    }
    return sb.toString();
}
Also used : Instruction(com.graphhopper.util.Instruction)

Example 7 with Instruction

use of com.graphhopper.util.Instruction in project PocketMaps by junjunguo.

the class NaviDebugSimulator method startDebugSimulator.

/**
 * The DEBUG_SIMULATOR will simulate first generated route on naviStart and trackingStart. *
 */
public void startDebugSimulator(final Activity activity, InstructionList instructions, boolean fromTracking) {
    if (!DEBUG_SIMULATOR) {
        return;
    }
    debug_simulator_from_tracking = fromTracking;
    if (instructions == null) {
        return;
    }
    if (debug_simulator_points == null) {
        debug_simulator_points = new ArrayList<GeoPoint>();
        for (Instruction ins : instructions) {
            for (int i = 0; i < ins.getPoints().size(); i++) {
                debug_simulator_points.add(new GeoPoint(ins.getPoints().getLat(i), ins.getPoints().getLon(i)));
            }
        }
    }
    final Location pLoc = new Location((String) null);
    final Location lastLoc = new Location((String) null);
    debug_simulator_run = true;
    runDelayed(activity, pLoc, lastLoc, 0);
}
Also used : GeoPoint(org.oscim.core.GeoPoint) Instruction(com.graphhopper.util.Instruction) GeoPoint(org.oscim.core.GeoPoint) Location(android.location.Location)

Example 8 with Instruction

use of com.graphhopper.util.Instruction in project PocketMaps by junjunguo.

the class NaviEngine method getUpdatedInstruction.

private NaviInstruction getUpdatedInstruction(GeoPoint curPos, PointPosData nearestP) {
    uiJob = UiJob.UpdateInstruction;
    if (instructions.size() > 0) {
        Instruction in = instructions.get(0);
        long partTime = 0;
        double partDistance = countPartDistance(curPos, in, nearestP.arrPos);
        partDistance = partDistance * partDistanceScaler;
        if (in.getDistance() <= partDistance) {
            partDistance = in.getDistance();
            partTime = in.getTime();
        } else {
            double partValue = partDistance / in.getDistance();
            partTime = (long) (in.getTime() * partValue);
        }
        long fullTime = countFullTime(partTime);
        Instruction nextIn = null;
        if (instructions.size() > 1) {
            nextIn = instructions.get(1);
        }
        NaviInstruction newIn = new NaviInstruction(in, nextIn, fullTime);
        newIn.updateDist(partDistance);
        if (!naviVoiceSpoken && nearestP.isDirectionOk() && speakDistanceCheck(partDistance)) {
            naviVoice.speak(newIn.getVoiceText());
            naviVoiceSpoken = true;
        }
        return newIn;
    }
    return null;
}
Also used : Instruction(com.graphhopper.util.Instruction)

Example 9 with Instruction

use of com.graphhopper.util.Instruction in project graphhopper by graphhopper.

the class Examples method routing.

@Test
public void routing() {
    // Hint: create this thread safe instance only once in your application to allow the underlying library to cache the costly initial https handshake
    GraphHopperWeb gh = new GraphHopperWeb();
    // insert your key here
    gh.setKey(apiKey);
    // change timeout, default is 5 seconds
    gh.setDownloader(new OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS).readTimeout(5, TimeUnit.SECONDS).build());
    // specify at least two coordinates
    GHRequest req = new GHRequest().addPoint(new GHPoint(49.6724, 11.3494)).addPoint(new GHPoint(49.6550, 11.4180));
    // Set vehicle like car, bike, foot, ...
    req.putHint("vehicle", "bike");
    // Optionally enable/disable elevation in output PointList, currently bike and foot support elevation, default is false
    req.putHint("elevation", false);
    // Optionally enable/disable turn instruction information, defaults is true
    req.putHint("instructions", true);
    // Optionally enable/disable path geometry information, default is true
    req.putHint("calc_points", true);
    // note: turn off instructions and calcPoints if you just need the distance or time
    // information to make calculation and transmission faster
    // Optionally set specific locale for instruction information, supports already over 25 languages,
    // defaults to English
    req.setLocale(Locale.GERMAN);
    // Optionally add path details
    req.setPathDetails(Arrays.asList(Parameters.Details.STREET_NAME, Parameters.Details.AVERAGE_SPEED, Parameters.Details.EDGE_ID));
    GHResponse fullRes = gh.route(req);
    if (fullRes.hasErrors())
        throw new RuntimeException(fullRes.getErrors().toString());
    // get best path (you will get more than one path here if you requested algorithm=alternative_route)
    ResponsePath res = fullRes.getBest();
    // get path geometry information (latitude, longitude and optionally elevation)
    PointList pl = res.getPoints();
    // distance of the full path, in meter
    double distance = res.getDistance();
    // time of the full path, in milliseconds
    long millis = res.getTime();
    // get information per turn instruction
    InstructionList il = res.getInstructions();
    for (Instruction i : il) {
    // System.out.println(i.getName());
    }
    // get path details
    List<PathDetail> pathDetails = res.getPathDetails().get(Parameters.Details.STREET_NAME);
    for (PathDetail detail : pathDetails) {
    // System.out.println(detail.getValue());
    }
}
Also used : PointList(com.graphhopper.util.PointList) InstructionList(com.graphhopper.util.InstructionList) Instruction(com.graphhopper.util.Instruction) GHResponse(com.graphhopper.GHResponse) ResponsePath(com.graphhopper.ResponsePath) PathDetail(com.graphhopper.util.details.PathDetail) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.jupiter.api.Test)

Aggregations

Instruction (com.graphhopper.util.Instruction)9 GHRequest (com.graphhopper.GHRequest)3 GHResponse (com.graphhopper.GHResponse)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3 GeoPoint (org.oscim.core.GeoPoint)3 RoundaboutInstruction (com.graphhopper.util.RoundaboutInstruction)2 Location (android.location.Location)1 WorkerThread (android.support.annotation.WorkerThread)1 ResponsePath (com.graphhopper.ResponsePath)1 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)1 InstructionList (com.graphhopper.util.InstructionList)1 PointList (com.graphhopper.util.PointList)1 PathDetail (com.graphhopper.util.details.PathDetail)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1