I am familiar with directional drilling used in oil exploration. What you have posted about is much, much easier.
First, they know how much pipe they have used. This lets then know how long the hole is. They have control on where the bit goes by controlling how hard they push it. As I understand it, they put heavy tools (called collars) right behind the bit. So, if they push just enough to overcome the friction of the pipe in the hole (rate of penetration is low), the hole angle will drop (below vertical). Push harder, and the angle climbs. Depending on the number of collars, they control how much build they can achieve. These techniques are usually suitable for short runs, like under a road or a creek/small river. Drilling with this set-up is known as drilling with “dumb iron”.
For longer runs, more exact drilling, they will run a mud motor, which is powered hydraulically or pneumatically. In these cases, the drill bit is attached to a motor at the end of the drill string. The drill string is not rotated, so they can but a “bent sub” right before the motor. A “bent sub” is like a short bent piece of pipe, bent at 2 to 5 degrees (sub is short for substitute, since it is substituted for a joint of pipe). So, by controlling where the bend is pointing (by making small rotations to the string), they can control where the bit goes.
As to the problem of knowing where they are, if they are close enough to the surface, they can run a strong acoustic or radio signal that can be detected at the surface. This is limited to being pretty shallow, though, and to give a number, I’d have to rely on a rectal extraction method (pull out of my ass) and say less than 100 feet or so below the surface. More than that, and they have to survey the hole; run logging instruments in the hole that records distance, inclination, and azimuth. Generally, these are run in the hole to make the survey, then retrieved and the data downloaded at the surface.
They do have technology that allows data communications between the surface and the logging tools. Known as wired drill pipe, this is an expensive option. It is very effective, but with the ability to send and receive data real-time to the driller, it can greatly reduce the amount of time needed to drill the hole. If you are interested in how the wired drill pipe works, look up Intelli-Serv as they are the only company that I know of that markets such a product.
I worked for over 30 years manufacturing drilling tools, drill pipe, mud motors, and other tools. Things are done very differently today than they were 30 years ago, and will be done differently next year than they are done today. I never worked on an active rig, but I can say that a lot of how they do it has to do with the guy running the equipment knows what he is doing (or at least, has a pretty good idea).