Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion from route duration to time #6

Open
AlysonTrizotto opened this issue Mar 21, 2022 · 1 comment
Open

Conversion from route duration to time #6

AlysonTrizotto opened this issue Mar 21, 2022 · 1 comment

Comments

@AlysonTrizotto
Copy link

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
Copy link
Owner

liodali commented Mar 23, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants