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();
}
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);
}
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;
}
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());
}
}
Aggregations