liodali / OSM-Routing-Client-Dart

flutter package for osrm client api and open source routing service
https://pub.dev/packages/routing_client_dart
MIT License
18 stars 12 forks source link

Conversion from route duration to time #6

Open AlysonTrizotto opened 2 years ago

AlysonTrizotto commented 2 years ago

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.

liodali commented 2 years ago

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