MagicMirror module that Retreives Transit Schedule for nearby routes, and displays the departure stops on Google Map, and displays departure times in table.
Note
Uses Google Direction Routes API, to get nearby bus stops and departure times. Google Direction Routes API is described below, but you don't to understand it to get it to work: https://developers.google.com/maps/documentation/routes/compute_route_directions
Module to be installed in the MagicMirror application, described in below link.
https://github.com/MagicMirrorOrg/MagicMirror
The MagicMirror application is built on the node.js application platform, and node.js package dependencies can be managed by npm application.
Directions API
Geocoding API
Maps JavaScript API
Maps Static API
Roads API
Routes API
Warning
Needs Google API key to work. You can obtain one here: https://console.cloud.google.com/apis/credentials. The key needs to have permissions to the API indicated above. To get a Google API Key, read my blog entry: https://www.tictawf.com/blog/using-google-cloud-apis/ But you will need to supply a credit card.
cd <MagicMirror root>/modules/
git clone https://github.com/studio-1b/MMM-GoogleBusSchedule.git
cd MMM-GoogleBusSchedule
npm install
Required is to replace API key, and coordinates of where you want bus stops.
{
module: "MMM-GoogleMapGpx",
header: "Buses Nearby",
position: "top_right",
config: {
width: 350,
height: 300,
apikey: "<GOOGLE_API_KEY>",
origin: {lat: <latitude >, lon: <longitude>},
ical: "<ical url>"
}
},
Key | Description |
---|---|
width 350 |
Width of Map |
height 300 |
Height of Map |
apikey (required) |
Google API key, as specified above (ie. ) |
origin (required) |
object with Latitude,Longitude (ie. {lat: 49.22652, lon: -122.94399} ) |
ical (optional) |
Ical URL is optional (ie. https://calendar.google.com/calendar/ical/basic.ics), but if supplied, it will retreive next available calendar entry with geocodable location, and posts driving path on map. Bus legs are added to table. |
cache (true) |
Save Bus Schedule data retreived from Google, save by day of week, and time retreived, and if matches previous data, don't retreive the rest |
The program checks directions in 0.25mi N, E, W and S, and displays all departure bus stops and their departure times, and shows it on table. Bus stop locations are also displayed on map.
Your Google API key can be expected to generate around 1800 requests per month, to the Route API, resulting in a cost of around $80, which is well below to $200 that Google gives for free, as of 2/26/2023. There is CachedSchedule branch, that will cache the Bus schedules retreived from Route API, and this should reduce the number of requests to Route API by 75%.