2002 Sonata intermittent speedometer

The speedometer on my 2002 Hyundai Sonata usually works, until it doesn’t. This happens most often on longer trips. The speedometer starts fluctuating between 0 and my current speed and eventually gives up entirely. I’ve asked several dealers what the problem might be, but they’ve all said they can’t find anything (of course it’s always working when I take it in.) When the speedometer is not working, neither is the odometer or the cruise control. What could it be?

I would first suspect a faulty speed sensor or connection to it.