Fall 2024
Ranking Map Routes by Safety
Chrome extension that re-ranks Google Maps routes by predicted safety, scored from 350,000 rows of crime, accident, and weather data.
- ml
- data
- frontend
Outcome
A Chrome extension that ranks Google Maps routes by safety rather than speed, scoring them with a Decision Tree Regressor over a 350,000-row dataset of crime, accident, and weather data. The team cut end to end scoring from 2 minutes to 7 seconds, a 17x speedup, by taking a dataset reload out of the inner loop.
I wrote the Flask orchestration layer: fetching alternative routes from the Google Maps Directions API, running each through the safety calculation, and assembling the response. I also built the live weather integration. Team of four at HackHarvard 2024, with Maxence Gilloteaux, Sam Chen and Marmik Patel.

The extension adds a Safety toggle beside Maps' own Time control and re-labels each route. The fastest route is not the safest one here, which is the whole idea.
- 1.Safety replaces time as the ranking criterion
- 2.Each alternative gets a risk label from the model's score, not from traffic
Motivation
Routing tools optimize for speed; SafeRoute ranks for safety instead. The team's stated motivation was that safety is a universal concern whether the risk is a collision or walking alone at night.
Built over a single hackathon weekend at HackHarvard 2024.
Experience, learning & skills
The first working version took 2 minutes to score a route and had to be brought down to 7 seconds before it was usable. The team also hit integration friction between the Python backend and the JavaScript extension, and a steep learning curve on data cleaning and encoding for the model.
- Built the Flask service that fetches alternative routes from the Google Maps Directions API and returns them ranked by safety
- Wrote the safety-score calculation that combines crash, crime, and weather signals into a single per-route number
- Integrated a live weather API into the score, including key handling and a fallback for missing readings
Technical details
Backend in Python: Requests, Beautiful Soup, and Pandas to collect and clean the data, and scikit-learn's Decision Tree Regressor to score routes. A 60,000-row accident CSV was joined against geographic data to produce the 350,000-row JSON the model reads. The frontend is plain JavaScript, HTML, and CSS injected into Google Maps.
The 2-minute to 7-second speedup came from the scoring loop. It walks a route segment by segment, intersecting the road network's junctions with the crash dataset. The original version re-opened and re-parsed the entire 350,000 entry JSON from disk on every segment, rebuilding a set of its keys each time, so an N-segment route parsed the whole dataset N times. Hoisting that load out of the loop left each segment as a set intersection against an in-memory dictionary. The same pass rebuilt intersection extraction to construct a node-coordinate dictionary once instead of rescanning the XML per node, and added gzip to the OpenStreetMap requests.