Google is great for so many things. Spelling, basic math, finding a song with just a couple lyrics, and navigating through traffic. But how does Google figure out what the traffic is like on a constant basis? Someone posted on every street, updating every couple minutes? Personal company traffic copters? Turns out it's your phone.
Google uses the data from smart phones to determine how congested a road is. Every phone since 2011 has come with GPS enabled to triangulate with towers, so no matter what your phone is being watched. Google simply uses this mandatory invasion of privacy to work for the greater good.
Google knows there are a lot of variables and simply counting the amount of phones in an area and how quickly they're traveling isn't enough to indicate traffic. They use complex algorithms to determine someone like a mailman who makes frequent stops, and has really specific thresholds that must be met to escalate the color of the road to more congested.
Privacy enthusiasts can choose to opt out of sharing their data, but Google assures users that they protect the data as best as possible. Even they aren't sure who the data is coming from.