Saturday, 17 November 2018

TravelTimeCalculator: Defining a SQLite Database for Directions

In order to reduce the number of requests to Google Directions API for directions, my app will need to save and reuse old queries to an Android SQLite database.

A SQLite query for directions will handle the following information:
  • Origin Latitude 
  • Origin Longitude 
  • Destination Latitude
  • Destination Longitude
  • The mode of transportation (DRIVING, TRANSIT, WALKING, BICYCLE)
  • Travel Time in seconds
  • Travel Duration in meters
The app will search for coordinates to find existing queries. In order to reduce the possible coordinates to a feasible number of coordinates, I'll cast the coordinates to integers, after multiplying by 1000. 

This means that the coordinate (13.00213121, 55.432923) will be converted to (13002, 55433). The highest rounded error will be: 

After querying, the database will be populated with data for recently used directions.

Whenether the user makes a new query, the database will start by finding all results that has origin and destination coordinates that are matching the query. The swapped coordinates will also count as hits. The query (13012,55605, 13002, 55605) shall find the directions above.

I'll use the Android SQLite tutorial as inspiration for the database.


One entry to the database might be


13002, 55605, 13012, 55605, "DRIVING", 240, 2000.

Those values that aren't defined will have the default value "NULL".

No comments:

Post a Comment