OSM-Routing-Client-Dart icon indicating copy to clipboard operation
OSM-Routing-Client-Dart copied to clipboard

Conversion from route duration to time

Open AlysonTrizotto opened this issue 3 years ago • 1 comments

Hello how are you? I'm having difficulties in getting the time conversion of the route returned by the library that is returned by "road.duration" right.

I have done so to convert ValueNotifier<String> tempoRota = ValueNotifier('00:00');

Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( tempoRota.value, style: TextStyle(fontSize: 30), ), ], ),

tempoRota.value = getStringToTime(road.duration);

`String getStringToTime(double valor) { if (valor < 0) return 'Tempo inválido';

valor = valor / 60;

int flooredValue = valor.floor();
double decimalValor = valor - flooredValue;
String hourValor = getHourString(flooredValue);
String minuteString = getMinuteString(decimalValor);

print('${hourValor}:${minuteString} min');

return '${hourValor}:${minuteString} min';

}

String getMinuteString(double decimalValue) { return '${(decimalValue / 60).toInt()}'.padLeft(2, '0'); }

String getHourString(int flooredValue) { return '${flooredValue % 24}'.padLeft(2, '0'); } `

However, it always gives me a value in hours, and depending on the length of the route, it doesn't give me the right travel time. So it only works for short routes. Routes that are longer in duration do not work.

AlysonTrizotto avatar Mar 21 '22 11:03 AlysonTrizotto

how did you know that it doesn't work for long routes and the distance is in seconds not in hours

liodali avatar Mar 23 '22 16:03 liodali