Methods of RouteListener called only in when user start his route (but not called when user near on the next turn)
katyavolkova opened this issue · 1 comments
katyavolkova commented
Device: Samsung J5
Android version: 6.0.1
Included dependency using Gradle:
compile 'com.mapzen:on-the-road:1.2.0'
Code:
` public class MyClass implements RouteCallback, RouteListener {
private static final String TAG = "MyClass";
private Polyline polyline;
private GoogleMap map;
private double[] myLoc, otherLoc;
private Router router;
private Route route;
private final RouteEngine engine;
private Speakerbox speakerbox;
public MyClass(Speakerbox speakerbox){
this.speakerbox = speakerbox;
router = new ValhallaRouter();
router.setHttpHandler(new MapzenHttpHandler(HttpLoggingInterceptor.Level.BODY));
router.setCallback(this);
engine = new RouteEngine();
engine.setListener(this);
}
public void setMap(GoogleMap map){
this.map = map;
}
// I call this method every time when have new location
public void setUserLocation(double myLat, double myLng){
if(route == null || !route.foundRoute() || engine == null)
return;
ValhallaLocation valhallaLocation = new ValhallaLocation();
valhallaLocation.setBearing((float) route.getCurrentRotationBearing());
valhallaLocation.setLatitude(myLat);
valhallaLocation.setLongitude(myLng);
ValhallaLocation onTheRoad = route.snapToRoute(valhallaLocation);
if(onTheRoad != null) engine.onLocationChanged(onTheRoad);
}
public void describeRoute(double myLat, double myLng, double otherLat, double otherLng){
this.myLoc = new double[]{Double.valueOf(myLat), Double.valueOf(myLng)};
this.otherLoc = new double[]{Double.valueOf(otherLat), Double.valueOf(otherLng)};
requestRoute();
Log.d(TAG, "describeRoute");
}
public void removeRoute(){
if(polyline != null){
polyline.remove();
polyline = null;
Log.d(TAG, "removeRoute");
}
}
private void requestRoute(){
router.clearLocations();
router.setLocation(myLoc);
router.setLocation(otherLoc);
router.setDriving();
//router.setLanguage(language);
router.fetch();
Log.d(TAG, "requestRoute");
}
@Override
public void success(Route route) {
this.route = route;
Log.v(TAG, route.getRawRoute().toString());
engine.setRoute(route);
int totalDistance = route.getTotalDistance();
int totalTime = route.getTotalTime();
int color = App.getStaticContext().getResources().getColor(R.color.green);
PolylineOptions options = new PolylineOptions().width(7).color(color).geodesic(true);
List<ValhallaLocation> nodes = route.getGeometry();
for (int i = 0; i < nodes.size(); i++){
ValhallaLocation location = nodes.get(i);
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
options.add(latLng);
}
polyline = map.addPolyline(options);
setUserLocation(myLoc[0], myLoc[1]);
}
@Override
public void failure(int i) {
Log.v(TAG, "" + i);
Toast.makeText(App.getCurrentActivity(), "Path distance exceeds the max distance limit", Toast.LENGTH_SHORT).show();
}
@Override
public void onRouteStart() {
String message = "route started";
Log.v(TAG, message);
}
@Override
public void onRecalculate(ValhallaLocation location) {
String message = "onRecalculate";
Log.v(TAG, message);
Toast.makeText(App.getCurrentActivity(), message, Toast.LENGTH_SHORT).show();
}
@Override
public void onSnapLocation(ValhallaLocation originalLocation, ValhallaLocation snapLocation) {
String message = "onSnapLocation";
Log.v(TAG, message);
//Toast.makeText(App.getCurrentActivity(), message, Toast.LENGTH_SHORT).show();
LatLng latLng = new LatLng(snapLocation.getLatitude(), snapLocation.getLongitude());
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng)
.bearing(snapLocation.getBearing())
.zoom(map.getCameraPosition().zoom)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
@Override
public void onMilestoneReached(int index, RouteEngine.Milestone milestone) {
String message = "onMilestoneReached";
Log.v(TAG, message);
String instruction = route.getRouteInstructions().get(index).getVerbalTransitionAlertInstruction();
Toast.makeText(App.getCurrentActivity(), instruction, Toast.LENGTH_SHORT).show();
speakerbox.play(instruction);
Log.v(TAG, instruction);
}
@Override
public void onApproachInstruction(int index) {
String message = "onApproachInstruction";
Log.v(TAG, message);
String instruction = route.getRouteInstructions().get(index).getVerbalPreTransitionInstruction();
Toast.makeText(App.getCurrentActivity(), instruction, Toast.LENGTH_SHORT).show();
speakerbox.play(instruction);
Log.v(TAG, instruction);
}
@Override
public void onInstructionComplete(int index) {
String message = "onInstructionComplete";
Log.v(TAG, message);
Instruction instruction = route.getRouteInstructions().get(index);
String instructionStr = instruction.getVerbalPreTransitionInstruction();
Toast.makeText(App.getCurrentActivity(), instructionStr, Toast.LENGTH_SHORT).show();
speakerbox.play(instructionStr);
Log.v(TAG, instructionStr);
}
@Override
public void onUpdateDistance(int distanceToNextInstruction, int distanceToDestination) {
String message = "onUpdateDistance";
Log.v(TAG, message);
//Toast.makeText(App.getCurrentActivity(), message, Toast.LENGTH_SHORT).show();
}
@Override
public void onRouteComplete() {
String message = "route completed";
Log.v(TAG, message);
Toast.makeText(App.getCurrentActivity(), message, Toast.LENGTH_SHORT).show();
speakerbox.play(message);
}`
katyavolkova commented
Cannot reproduce