Search in sources :

Example 1 with InstructionAnnotation

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

the class TargetDirComputer method createTargetdirResponse.

public GHResponse createTargetdirResponse(double fromLat, double fromLon, double toLat, double toLon) {
    GHResponse resp = new GHResponse();
    PathWrapper pr = new PathWrapper();
    PointList pl = new PointList();
    pl.add(fromLat, fromLon);
    pl.add(toLat, toLon);
    pr.setPoints(pl);
    double distance = GeoMath.fastDistance(fromLat, fromLon, toLat, toLon);
    distance = distance * GeoMath.METER_PER_DEGREE;
    pr.setDistance(distance);
    double distKm = distance / 1000.0;
    // 50km == 1h
    double hours = distKm / 50;
    if (Variable.getVariable().getTravelMode() == Variable.TravelMode.Bike) {
        hours = hours * 3.0;
    }
    if (Variable.getVariable().getTravelMode() == Variable.TravelMode.Foot) {
        hours = hours * 9.0;
    }
    long timeMs = (long) (hours * 60.0 * 60.0 * 1000.0);
    pr.setTime(timeMs);
    InstructionList insL = new InstructionList(createEmptyTranslator());
    int sign = Instruction.CONTINUE_ON_STREET;
    String name = "direction to target";
    InstructionAnnotation ia = InstructionAnnotation.EMPTY;
    Instruction ins = new Instruction(sign, name, ia, pl);
    ins.setDistance(distance);
    ins.setTime(timeMs);
    insL.add(ins);
    pr.setInstructions(insL);
    resp.add(pr);
    return resp;
}
Also used : PointList(com.graphhopper.util.PointList) PathWrapper(com.graphhopper.PathWrapper) InstructionList(com.graphhopper.util.InstructionList) Instruction(com.graphhopper.util.Instruction) GHResponse(com.graphhopper.GHResponse) InstructionAnnotation(com.graphhopper.util.InstructionAnnotation)

Aggregations

GHResponse (com.graphhopper.GHResponse)1 PathWrapper (com.graphhopper.PathWrapper)1 Instruction (com.graphhopper.util.Instruction)1 InstructionAnnotation (com.graphhopper.util.InstructionAnnotation)1 InstructionList (com.graphhopper.util.InstructionList)1 PointList (com.graphhopper.util.PointList)1