This is a very real problem that interstellar voyagers such as those on Star Trek's starship Enterprise would need to address. But in fact, astronomers have already suggested a way in which this might be solved using radio ‘beacons’ known as pulsars.
Pulsars are rapidly spinning neutron stars – the corpses of massive stars that died in supernova explosions. When a massive star reaches the end of its life, its outer layers are thrown off in a vast explosion, leaving behind a collapsed core with the mass of the Sun, but shrunk into a volume that is only around 10 km across.
In much the same way as an ice skater spins faster by drawing in her arms, these collapsed neutron stars spin very rapidly – up to tens or even hundreds of times a second. Importantly, as they spin, they send beams of radio waves sweeping around the sky rather like a lighthouse.
Astronomers now know of many hundreds of these radio pulsars scattered around the Galaxy, and they each spin at their own characteristic rate. For instance, the object known as the Crab pulsar (the relic of a supernova explosion seen to occur in the year 1054) spins at a rate of about 30 times per second, so its radio signal repeats every 33 milliseconds.
Astronomers have also plotted precisely where each of these known pulsars is located in the three-dimensional space of the Galaxy.
So, all that an interstellar traveller would need to do in order to determine their position is to locate three of these pulsars, measure the direction from which the signal is coming, and from the unique pulsation period in the signal, identify just which three pulsars they had detected.
By simple trigonometry, they would then be able to triangulate between the three signals to determine their unique position in space.
In fact, the plaques sent from Earth on-board the Pioneer 10 and 11 spacecraft carried just such information, encoding the position of Earth in terms of its location with respect to certain known pulsars. If an alien were to pick up the plaque, they would be able to work out just where it came from!