We all know that our apps often need location to work. We have also heard that we get the location using GPS. But what is GPS? How does GPS work?
Table of Contents
How does GPS work?
GPS is the Global Positioning System GPS). It is a radio navigation system. The GPS system derives our device’s location utilizing a constellation satellites. Originally the constellation contains 24 satellites, and now there are about 31 satellites in the system. OK, but how does GPS work? Why do we need so many satellites? I mean, how does GPS derive the location for us?
The way to obtain the location is called “triangulating”. The logic behind is simple: we have 24 satellites revolving on an orbit around the earth. The orbit is known, which means we know how high all the satellites are and where they should be in the space at a given time. Now, if we can measure the distance of our devices to these known satellites (at least 3 or 4 of them), we can figure out where the device is.
What is triangulating?
For simplicity, let’s consider the 2D case. Imagine we know only the distance from one point (satellite). We have the position of the origin point, and we have a measurement of the distance d. So where can we be? It has to be on one of the point on the circle with radius d around the origin point! Now, if we add another origin point (the second satellite) and another measurement to that point, we can draw a second circle. The intersections of these two circles, i.e. two points, are our potential location. We can then add the third circle around the third origin point (the third satellite). We will then be able to choose one of the point and resolve our location on a 2D space.
In reality, we typically do not need to add the one last satellite measurement though. This is because one of the two points would be too ridiculous to be the true location and therefore we can simply discard it. So we can conclude two satellites are sufficient.
In 3D space, which is the reality, we are not drawing circles but spheres. Therefore, we need 3 satellites to come down to one point.
Now let’s go a little deeper. Our real challenge behind this concept is how do we measure the distance accurately. This technique is called “ranging”. The way it works is by measuring the time of flight of a signal from satellite. Since the signal travels by speed of light, if we know the time difference from when the signal starts traveling from the satellite to when it arrives on our device, we can calculate the distance. We get it by the simplest equation from physics:
- Velocity x Time = Distance
However it is easier said than done. Even if we can receive the signal on our device, we need to figure out a few things to really understand how does GPS work:
- How do we know which satellite transmitted the signal?
- How do we know when the signal starts traveling?
Which satellite transmitted the signal?
In a GPS system, we solve the problem 1 by assigning to each satellite a pseudorandom code. When transmitting the signal, the signal carries a special code. The signal looks like a special form that is dedicated to that satellite. So on the receiver side, we will be able to differentiate which satellite transmitted the received signal.
How long did it take for the signal to travel?
But how about the timing? This is a really difficult problem so the smart scientist came up with a magical solution. We let the receiver generates the same signal at the same time as the satellite. Without better analogy, I can only ask you to imagine you and your friend on a far away point try to speak the same sentence at the same time. That’s what the receiver and the transmitter do in this case. The receiver then will receive the signal from the transmitter after a while (because of the long distance between satellite and the device). By comparing how far away the received signal is to the signal it generated itself, the receiver decides how long has passed since the signal transmission from the satellite.
This method requires the transmitter and the receiver are always in sync. And that is really important, because even if their timing is off by just 1/1000 second, the calculation would have been off by ~200 miles. On the satellite side it is not difficult to make sure of the timing because satellites are expensive and have the most precise atomic clocks on board. However this is a lot more challenging for the receiver in our device. It is hard for us to throw in 50K for a GPS receiver to get the very precise atomic clock.
Solving the timing inaccuracy
The cure is to add one more measurement to do a cross-check. As we know, if our clock on the receiver has been accurate, the 4th measurement would have been overlapping with the resolved location using the previous 3 measurements. If that is not the case, it would mean our clock is off. In this case, we apply a trick to search for a time offset (adjust our clock) which will make the 4 measurements settle on the same location. For example my clock may be off by 1/1000 second, if I reduce this 1/1000 second from all measurements and in that way I can make them all resolve to the same location, I would conclude this is the right answer. The only drawback of this method is we need 1 more measurements.
Final remarks about other GNSS systems
Hopefully now we have a good understanding about how does GPS work. One final point I would like to mention is the term GPS is actually a bit confusing. GPS as a navigation system is owned by the United States. There are actually other systems for the same purpose, such as GLONASS by Russia, Galileo by EU, QZSS by Japan and BeiDou by China. All these systems use set of satellites to carry out location of the receiver with some differences, e.g. the orbit height, revolution speed etc and there are a bit difference in terms of their accuracy. However what really matters to us is to know there are different systems operated by different countries so the global navigation system is not solely controlled by one government. All these systems, despite their owner, are a kind of GNSS, or Global Navigation Satellite System.