Skip to content

mapup/tolltally-toll-for-route-tomtom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

toll-tomtom

Multi-language examples showing how to enrich a TomTom route with real-time toll costs using the TollGuru API. Given a source and destination, the code fetches the route from TomTom, encodes it as a polyline, and queries TollGuru for toll costs across all payment types (tag, cash, credit card). Implementations in Python, JavaScript, Ruby, and PHP.

TollGuru Capabilities

  • Supported geographies — North America, Europe, Asia, Australia, Latin America
  • Supported vehicle types — car, truck, motorcycle, bus, RV, and more
  • Payment options — tag transponder, cash, licence plate, credit card, prepaid (in local currencies)
  • Time-based tolls — pass departure_time for accurate rates on express lanes and time-of-day pricing
  • All toll system types — barrier, ticket system, and distance-based tolling
  • Supported map services — edit the source param to use a different mapping platform
  • Truck parameters — height, weight, hazardous goods, tunnel category, etc.
  • API parameter examples — full request body variations

Architecture

  • Client geocodes source/destination via TomTom Geocoding API (address → lat/lon)
  • Client calls TomTom Routing API to get ordered route points
  • Route points encoded into a Google-format polyline
  • Polyline POSTed to TollGuru /complete-polyline-from-mapping-service endpoint
  • TollGuru returns toll costs per payment type (tag, cash, credit card) per toll plaza
  • All calls are synchronous HTTP — no server, no datastore, no queue
  • Auth via API keys in environment variables (TOMTOM_API_KEY, TOLLGURU_API_KEY)
  • Test harness reads source/destination pairs from CSV, writes results to CSV
  • See docs/architecture.md for details

Prerequisites

Local Setup

Set environment variables first:

export TOMTOM_API_KEY=your_tomtom_key
export TOLLGURU_API_KEY=your_tollguru_key

Python

cd python
pip install -r requirements.txt
python TomTom.py

JavaScript

cd javascript
npm install
node index.js

Ruby

cd ruby
bundle install
ruby main.rb

PHP

cd php
php php_curl_tomtom.php

Running Tests

Python — reads python/Testing/testCases.csv, writes testCases_result.csv

cd python/Testing
python Test_TomTom.py

Ruby — reads ruby/TestCases/testCases.csv, writes testCases_output.csv

cd ruby/TestCases
ruby test_ruby.rb

JavaScript and PHP have no automated test suite.

Deployment

No server component. Scripts run as one-shot CLI tools. To deploy in CI or a scheduled job:

  1. Set TOMTOM_API_KEY and TOLLGURU_API_KEY as secrets in your environment
  2. Install dependencies for the target language
  3. Run the entry-point script for that language

Config

All configuration is via environment variables. No config files.

Variable Required Description
TOMTOM_API_KEY Yes TomTom Routing/Geocoding API key
TOLLGURU_API_KEY Yes TollGuru toll calculation API key

Source/destination and vehicle type are set as constants in each implementation's entry-point file.

Known Limitations

  • No caching — every run makes live API calls
  • No retry logic on transient failures
  • PHP disables SSL peer/host verification (CURLOPT_SSL_VERIFYPEER, CURLOPT_SSL_VERIFYHOST set to false)
  • Ruby Gemfile locks to Ruby 2.6.10
  • Single route per invocation; no batch mode in main scripts (test harness does batch via CSV)
  • TollGuru returns costs for the first route leg only if multiple legs exist
  • Supported geographies and vehicle types depend on TollGuru coverage — see country coverage and vehicle types

Docs

License

ISC License. Copyright 2020 TollGuru. See individual language READMEs for full text.

About

Code examples for calculating tolls on TomTom routes as part of in-trip billing

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors