This a module for the MagicMirror. It displays travel time between two locations, using the Google Distance Matrix API to retrieve the commute time. This code base is forked and modified from the MMM-Traffic module to make it work with the new Google API.
Navigate into your MagicMirror's modules folder and execute these commands:
git clone https://github.com/huyphan/MMM-SimpleGoogleTraffic
cd MMM-SimpleGoogleTraffic
npm installFollow Google's instruction to create an API Key. Make sure you give it permissions to use the JavaScript Map API and the Distance Matrix API.
You can use a global MagicMirror/css/custom.css file to customize the styles for each line of MMM-Traffic separately. Each line has its own class that should be used to apply styles:
.mmmtraffic-firstline.mmmtraffic-secondline
For example, this css
.mmmtraffic-firstline {
font-size: 40px;
color: yellow;
}
.mmmtraffic-secondline {
color: green;
}
See here for instructions on how to use Google Maps webpage/app to get coordinates for your origin/destination.
Note: Google maps coordinates are latitude,longitude, but Mapbox uses longitude,latitude so be sure to reverse what you copy from Google.
| Option | Description | Type | Example |
|---|---|---|---|
apiKey |
Google Maps API Key | string | - |
originCoords |
longitude,latitude of the origin location. |
string | '-84.504259,33.882107' |
destinationCoords |
longitude,latitude of the origin location. |
string | '-84.504259,33.882107' |
| Option | Description | Type | Default Value | Supported Options |
|---|---|---|---|---|
mode |
Change the module to cycling or walking. | string | 'driving' |
'walking' 'cycling' |
language |
Define the commute time language. | string | config.language |
Any language string |
interval |
How often the traffic is updated in milliseconds. | integer | 300000(5 minutes) |
|
showSymbol |
Whether to show the car symbol or not. | boolean | true |
Use these options to customize/translate the module's text.
*Note: See tokens below to see what tokens will be replaced with real values in firstLine/secondLine.
| Option | Description | Type | Default Value | Token Replacement |
|---|---|---|---|---|
loadingText |
The text used when loading the initial duration. | string | 'Loading...' |
❌ |
firstLine |
The main line of the module | string | 'Current duration is {duration} mins' |
✔️ |
secondLine |
The second line of the module, appears below the first line in smaller, dimmer text | string | undefined |
✔️ |
| Token | Value |
|---|---|
{duration} |
The driving time returned from the mapbox API |
Using these options to hide the module when you're not using it will save API calls, allowing you to have a shorter interval or more MMM-Traffic modules without getting rate limited.
| Option | Description | Type | Default |
|---|---|---|---|
days |
Which days of the week to show the traffic module, with 0 being Sunday | Array[int] | [0, 1, 2, 3, 4, 5, 6] |
hoursStart |
What time to begin showing the module on the days it shows, 24 hour time | String | "00:00" |
hoursEnd |
What time to stop showing the module on the days it shows, 24 hour time | String | "23:59" |
{
module: "MMM-SimpleGoogleTraffic",
position: "top_left",
config: {
apiKey: "your_key_here",
originCoords: "-84.398848,33.755165",
destinationCoords: "-84.504259,33.88210",
}
},{
module: "MMM-SimpleGoogleTraffic",
position: "top_left",
config: {
apiKey: "your_key_here",
originCoords: "-84.398848,33.755165",
destinationCoords: "-84.504259,33.88210",
showSymbol: false,
firstLine: "{duration} mins"
}
},{
module: "MMM-SimpleGoogleTraffic",
position: "top_left",
config: {
apiKey: "your_key_here",
originCoords: "-84.398848,33.755165",
destinationCoords: "-84.504259,33.88210",
firstLine: "{duration} mins",
secondLine: "Coffee Run"
}
},{
module: "MMM-SimpleGoogleTraffic",
position: "top_left",
config: {
apiKey: "your_key_here",
originCoords: "-84.398848,33.755165",
destinationCoords: "-84.504259,33.88210",
firstLine: "{duration} mins",
secondLine: "Home To School",
}
},
{
module: "MMM-SimpleGoogleTraffic",
position: "top_left",
config: {
apiKey: "your_key_here",
originCoords: "-84.398848,33.755165",
destinationCoords: "-84.504259,33.88210",
firstLine: "{duration} mins",
secondLine: "Home To Work"
}
},This setup would show one route for Monday, Wednesday, and Friday, and another for Tuesday and Thursday. It would only show between 07:00 and 09:00 each day. It would be completely hidden on weekends.
{
module: "MMM-SimpleGoogleTraffic",
position: "top_left",
config: {
apiKey: "your_key_here",
originCoords: "-84.398848,33.755165",
destinationCoords: "-84.504259,33.88210",
firstLine: "{duration} mins",
secondLine: "School",
days: [0,2,4],
hoursStart: "07:00",
hoursEnd: "09:00"
}
},
{
module: "MMM-SimpleGoogleTraffic",
position: "top_left",
config: {
apiKey: "your_key_here",
originCoords: "-84.398848,33.755165",
destinationCoords: "-84.504259,33.88210",
firstLine: "{duration} mins",
secondLine: "Work",
days: [1,3],
hoursStart: "07:00",
hoursEnd: "09:00"
}
},| Day | View |
|---|---|
| Mon/Wed/Fri | ![]() |
| Tu/Th | ![]() |






