use of com.graphhopper.util.InstructionList in project graphhopper by graphhopper.
the class RouteResourceClientHCTest method readFinishInstruction.
@ParameterizedTest
@EnumSource(value = TestParam.class)
public void readFinishInstruction(TestParam p) {
GraphHopperWeb gh = createGH(p);
GHRequest req = new GHRequest().addPoint(new GHPoint(42.507065, 1.529846)).addPoint(new GHPoint(42.510383, 1.533392)).putHint("vehicle", "car");
GHResponse res = gh.route(req);
InstructionList instructions = res.getBest().getInstructions();
String finishInstructionName = instructions.get(instructions.size() - 1).getName();
assertEquals("Arrive at destination", finishInstructionName);
}
use of com.graphhopper.util.InstructionList 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());
}
}
use of com.graphhopper.util.InstructionList 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;
}
Aggregations