Skip to content

A MagicMirror module that shows travel times taking into account Google traffic information

Notifications You must be signed in to change notification settings

kevin-og/MMM-GoogleTrafficTimes

 
 

Repository files navigation

Module: Google Traffic Times

A module for the MagicMirror that displays driving times from a location to one or more destinations based on Google Maps Traffic information. As it uses the times in traffic the values are dynamic as long as there is reasonaby accurate traffic detail available to Google in your area. The results are displayed in response bubbles which have a white circle as long as the travel time in traffic is the same or shorter than the equivalent Google holds excluding traffic data. If the in traffic travle time is longer then th circle border changes to red in order to quickly identify the increased travel time.

Table of contents

Installation

Navigate into your MagicMirror's ~/MagicMirror/modules folder and execute

git clone https://github.com/Jacopo1891/MMM-GoogleTrafficTimes.git 

A new folder will be created, please navigate into it. Once in ~/MagicMirror/modules/MMM-GoogleTrafficTimes run:

npm install

to install the module and dependencies.

Using the module

To use this module, add it to the modules array in the config/config.js file:

var config = {
    modules: [
        {
            module: 'MMM-GoogleTrafficTimes',
            position: 'top_left',
            config: {
                key: 'YOUR_KEY',
                origin: 'SW1A 1AA',
                destinations: [
			        {
			        	name: "Work",
			        	address: "SW1A 2PW"
			        },
			        {
			        	name: "Gym",
			        	address: "XXX"
			        }
		        ],
                avoidHighways: false,
                avoidTolls: false,
                mode: 'DRIVING',
                language: "en-EN",
                offsetTime: 25,
                debug: false
            },
        }
    ]
}
  • key: your Google API key as described in the relevant section of this readme
  • origin: This is the location all travel times to the destinations below will be measured from.
  • destinations: Those are the locations you need travel times to (min 1, max 20).
  • avoidHighways: true or false, controls whether Highways are avoided (true) or utilised (false) in routing.
  • avoidTolls: true or false, controls whether Tolls are avoided (true) or utilised (false) in routing.
  • mode: The mode of transport to use when calculating directions, DRIVING (default), cycling or walking (requests cycling/walking directions via bicycle paths/pedestrian paths - where available)
  • language: Set languages, default en-EN. (fr-FR, de-DE, it-IT)
  • offsetTime: Percentage to decide if there is traffic and show symbol. See paragraph to undestand logic and edit properly.
  • debug: true or false, shows logs on console (node_helper -> backend, module -> browser).

The Destinations need to be entered in the form

[
    {
       	name: "Work",
       	address: "SW1A 2PW"
    }
]

In the example config for Destination 1 we have a Label of Work with an Address of SW1A 2PW.

The Label name appears as the title for each result as shown in the Example Screenshot below.

In this release the origin and destination addresses have been tested across a large number of countries but certainly not all.

Whilst the Google API can accept a multitude of formats from addresses to lat&long co-ordinates this script has some matching code to make the results format nicely and this could have issues with an as yet untried address format.

Google API Key

In order to use this module you will need a Google Maps API which is available from the Google GCP console. You will need to enable the following APIs for your key, Maps JavaScript API, Geocoding API, Distance Matrix API.

Offset Time

To determine if the road is busy or not, I decided to add the optimal time (meaning without traffic by Google Matrix) with an offset obtained using this simple formula: optimalTime + (optimalTime * offset) If the estimated time from Google Matrix is greater than this value, it means there is traffic, and the symbol is displayed. By default, the offset is set to 25%, which seems like a good compromise.

Debug

  1. Stop any running instance of MagicMirror2.
  2. Make sure you are in the main directory of your project.
  3. Set debug: true on config.js as described in installation section.
  4. Execute the following command to start to see all logs.
npm start dev

or

npm start dev | grep MMM-GoogleTrafficTimes

to see only MMM-GoogleTrafficTimes's logs.

Example Screenshot

  • Minimal

alt text

  • Default

alt text

  • Multiple

alt text

  • Details (with traffic)

alt text

Suggestions

Please feel free to raise an issue on GitHub for any features you would like to see or usage issues you experience and I will endeavour to address them.

Buy me a coffee

Find it useful? Please consider buying me or other contributors a coffee.

blue-button

About

A MagicMirror module that shows travel times taking into account Google traffic information

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 98.1%
  • CSS 1.9%