Does Pokemon Go detect and care whether you are riding a bike (or driving a car, for that matter) when hatching an egg, or do you have to be on foot?
You can hatch an egg, as long as you're under 20mph. So walking, cycling, or even driving slowly counts towards hatching the egg.
It isn't calculated by the pedometer, but by the distance traveled by GPS. So examples such as hanging a phone from a ceiling fan work too.