To put it simply, taxi meters measure distance and time. They then convert those measurements into a fare. Taxi fares are set by the area the taxi cab operates in -- in other words, it might cost more to travel the same distance or time in one city than it does in another. Fares may also change based on how many people are in the taxi, if the driver has to help you with your bags and if the taxi has to cross state or municipal lines to get you where you're going.
No matter where they operate, however, all taxi meters measure the distance a cab covers, plus any time spent waiting. That way, the driver gets compensated for time, so they don't lose out on money just because they're stuck in traffic. It's also why a cab ride from point A to point B may cost you more when there's traffic than when there's not, even if the distance covered is the same.
A taxi meter uses electric pulses to measure both distance and time. To get the distance traveled, the meter relies on a sensor attached to the cab's transmission. The sensor sends an electric pulse to the meter every time the cab travels a given distance. Inside the meter itself is a timer that sends out a pulse when a set amount of time passes. Pulses come from either sensor at intervals that are smaller than the fare interval. For example, a cab might charge you based on every 100 yards (91.4 meters) of travel, but the distance meter will pulse at each yard (0.9 meters). When the meter gets 100 pulses, it adds to the amount of the fare.
Here's an example of fares from New York City. Just hailing a cab and getting in will cost you $2.50. For every fifth of a mile (0.3 kilometers) you travel, 40 cents is added to the fare (a fifth of a mile is four city blocks). For every minute the cab sits without moving, another 40 cents gets added to the fare.
Real traffic conditions aren't that simple, however. In a typical New York cab ride, you'll deal with stop-and-go traffic. To deal with stop-and-go traffic, meters merge calculations from both the time and the distance sensors, counting whichever pulse -- time or distance -- arrives first. Remember, the pulses come more often than the actual distance or wait time. So, if you wait 30 seconds in traffic and then cover two blocks in New York City, the taxi meter will merge the two and add 40 cents to the fare: 20 cents for the distance traveled and 20 cents for the time spent waiting.