Saturday, 9 March 2019

TravelTimeCalculator: Applying Settings

In this post, I'll use the values in the settings to estimate the cheapest travel mode.

The DBHelper method getAllDistanceDuration is expanded to return cost as well. It is using the following parameters:
  • Origin 
  • Destination
  • Emission cost (from settings)
  • Time cost (from settings)
  • Start and stop time for bicycling (from settings)
  • Start and stop time for driving (from settings)
  • Cost per kilometer for driving (from settings)
  • Emissions per kilometer for driving (from settings)
  • Ticket cost for transit (from settings)
  • Emissions per kilometer for transit (from settings)
I query the distances and durations from the database:

The values are stored in an array of integers.

The settings are retrieved from SharedPreferences.
I calculate the relevant costs and compare them with each other. The smallest cost is returned from the function,
Calculation of costs from the database. 
Finally, I update the marker with the shortest cost and the corresponding mode of transport.

Finally, some notes about bugs for this project:

One issue was unrealistic calculations for travel mode; "DRIVING", that is solved now.

Two issues are remaining:
The second one will be tricky and the first one probably needs some Googling.

Once those two issues are solved and I've cleaned the code, I'll stop developing this app. In the next blog post, I'll discuss the journey of learning to build an Android App, and why this app won't reach Google Play for now. 

No comments:

Post a Comment