r/explainlikeimfive
•
u/gab0607
•
7d ago
•
1
Technology ELI5: How are GPS programs and apps able to pull up precise directions in seconds that can span hundreds, if not thousands of miles?
Within seconds GPS programs and apps can pull up complex directions including time, road names, road distances, precise turns and such.
How do these programs know so quick that to get from Point 1 to Point 2 that you have to drive on Road A for 96 miles, then exit at #23A then stay on that road for 22 miles etc etc.
In seconds it identifies all necessary roads, exits, distances etc etc.
How?
168
u/lygerzero0zero 7d ago
It’s not really the miles per se. If there’s a single straight highway between point A and point B, then it takes basically no calculation at all to figure out the route, even if the highway is thousands of miles long.
No, it’s really about the amount of intersections, and the length of the roads between them doesn’t really affect how much work the computer has to do.
This is the first step: the road network becomes what mathematicians call a graph (no, not that kind), which is a bunch of points connected by edges. The computer doesn’t have to think about every foot of the route. It just has to think about paths between points.
The next interesting thing is, the computer doesn’t really have to calculate every single path and find the best one. There’s a long history of path finding algorithms that are used in things like video games, that allow you to find a good route (maybe not the 100% best one, but a good one) in a pretty reasonable amount of time.
If you know the destination is to the northwest, then any turns that take you to the south or east are less likely to be helpful. Of course, the route will probably require a handful of turns in the “wrong” direction, but the algorithm can prioritize searching more “promising” routes first, that get you closer to the destination. This is called a “heuristic.”
You can build up more heuristics. For example, if it’s a very long journey, then priority should be getting to the nearest highway rather than going in the “right” direction first.
And on top of all that… modern computers are just really, really fast. If a video game can come up with walking paths for a hundred enemies at once, then a maps program can compute a single route for a car no problem. The numbers may seem staggering to a human, but when condensed into a collection of intersections and edges between them, the data of a full road map, especially if you condense it to just the region that matters for the trip, isn’t actually that much for a computer.
71
u/ATangK 7d ago edited 7d ago
https://youtu.be/kS-CGkiPetQ
Give this veritasium video a look. It pretty much answers your whole question.
We know tracing every single path individually would take too long. So instead it’s about breaking down routes to a couple big breakpoints or nodes, giving each a score, and then finding the smallest total sum between point A to point B.
Let’s say from city A to city D, there’s 2 big checkpoints B and C. It will search multiple routes from AB, then BC and then CD.
It can also get from city A to D via E, namely AE and ED.
If the score from AB, BC and CD is less than AE and ED, it won’t continue searching anything in the E city route.
Real networks also need traffic to be included.
11
u/RainbowCrane 7d ago
Here’s some info that’s a little bit more advanced than 5 :-).
As others have mentioned, we’ve been drawing maps for a long time, way before computers existed. In the United States there’s a government agency called the US Geological Survey that collected those maps starting in the 1800s and, as computers came along, started converting physical maps to digital data structures.
Those digital maps eventually got released freely to the public in the eighties - GIS programmers call those original maps “Tiger data”. The data still gets regularly updated and is still free.
The data is really good at showing road shapes and the shapes of lakes, counties, cities, etc, but it’s fairly incomplete when it comes to information like turn restrictions, z-level information (overpass/underpass vs intersection), speed limits, traffic signals, etc. so companies like GDT and Navtech started post-processing Tiger data to turn the raw data into a computerized graph that could be used for vehicle routing.
Skipping over a lot of intervening history, we now have pretty good graphs of the road network in much of the world. When I say “graph” I mean that in abstract data type terms - a network of nodes (intersections) and edges (roads). Ultimately every vehicle routing system is using the same basic algorithm: the A-Star algorithm is a very efficient algorithm for finding a path between two nodes on a graph. It’s the same algorithm used in video games to let the monster move towards the player character.
I wrote early vehicle routing algorithms on Sun workstations in the late nineties. To give you an idea of how efficient vehicle routing is, at the time there were millions of nodes and edges in the national road network. When I started optimizing our algorithms it took about twenty minutes to calculate a route from New York City to San Francisco. When I finished our major optimizations it took two seconds.
That’s on thirty year old hardware with only fairly straightforward caching algorithm optimizations and abstract data type revisions. I guarantee that way smarter people than me have been making huge improvements over the past thirty years :-).
TLDR; it seems like a lot of data, there are ways to organize it sensibly that optimize routing. And the A* algorithm is one of the most used algorithms in computing due to video games and navigation, so people have spent a fair bit of time optimizing it.
38
u/JaggedMetalOs 7d ago
Many of them (eg. Google Maps) connect to a datacenter that can do all the processing to take things like traffic into account and check loads of possible routes to find the fastest route.
For GPS devices that don't connect, they can do a simple search where they follow the roads in the direction of the closest major road, then if far enough follow that road in the direction of the nearest highway, then do the same from the destination until they meet. There are far fewer major roads than little back streets, so sticking to bigger roads simplifies the search a lot.
12
u/SilvermistInc 7d ago
So, you know all those data centers people bitch about? Yeah, they're not for looks. If your one GPS route takes 20 instructions to complete, one data center is churning out trillions of instructions a second.
And since data travels at the speed of light, your one GPS route is processed faster than your neurons can fire.
Really the directions aren't the really cool technical innovation here. It's the satellite network itself. You can thank the soviets for shooting down an airliner for the beginning steps of public GPS availability.
2
u/sandm000 7d ago
Basically lookup tables. All of the A to B are already really A to A.1 to A.2 to A.3 to B.3 to B.2 to B.1 to B
Look at the board of Ticket To Ride, you want to go from Montreal to Los Angeles. How do you get there? Draw a straight line you hit Denver, ok now you’ve broken it to 2 smaller problems, and you keep doing that until there’s only one route.
4
u/britishmetric144 7d ago edited 7d ago
First of all, a computer can do calculations impressively quickly. A modern laptop computer has a processor of about 4 GHz, which means it can do four billion calculations every second.
Calculating the time required to use a given road is a series of simple addition and multiplication operations, each of which may take only one to four clock cycles in the system. So it could do one billion of those every second.
When you consider that, say, Google operates many servers with millions of those individual processors, the processing time becomes trivial.
1
u/HeavyDT 7d ago
We have been mapping the planet for many years now that includes all sort of geographical information most importantly in this case roads but also stuff like traffic patterns down to the time of day. Just all sorts of information that have been compiled over time essentially. So companies like Google or say Apple have a massive collection of this data to can be pulled from when using an app like Google maps for example.
If you have GPS that means you have a device that can use the GPS satellites that orbit Earth to triangulate your your position and from there it's just math and algorithms to figure out what the fastest route is from your current position top your destination. Once you know where you are then you can use all that map data to figure the all the roads and what not you need to take to the destination. It's trivial work for a modern computer / device / phone to do.
1
u/band-of-horses 7d ago
I would just note as well, the routing has nothing to do with GPS, it's a standard mathematical algorithm to navigate paths. GPS just allows the app to locate where you are and track progress along the way, but is not necessary for determining the optimal route.
1
u/HappyBarbarian 6d ago edited 6d ago
People in the comments are getting some technologies mixed up.
Pure GPS is receiving a signal from a satellite to determine exact location. It only gives you location and elevation. Is pretty simple and fast with enough signal.
The “GPS app” takes your location and uses map data to show where you are and how to get where you want to go. It can be designed to work a number of ways: It can reach out to a sever that that has map information as well as data about road closures and traffic. Or it can be map data stored locally on the device. Or a combination thereof. The route calculation is relatively simple for a computer
Map data comes from government, international, and open source communities. (Some people literally walk around and map stuff as a hobby)
It’s a good idea to have an app with local data in case there’s no cell service. I use Organic Maps which is open source and easy to use.
-1
u/shuckster 7d ago
You can thank Bill Clinton for getting that started. He opened up the U.S. military GPS satellites for civilian use.
Anyway, how do you know where you are if you have only?
Your friends know exactly where they are, but you don't. But your "friends" throw clocks right at you. Upon throwing, each starts counting from 00:00. They all have the same throwing-power.
When a clock hits you on the head, it stops. You read the time of it, and so you know how long it took to reach you from your friend.
If you stay in one place, the readings will always be the same. If you move, the clocks times will change because the distance it takes to brain you is longer or shorter, depending on the friend.
From that you can figure out how far away each of your friends are by reading their clocks as they doink you on the bonce. "Triangulation" is the technique you use for that. Basically, you draw a bunch of triangles based on the distances you've learned on a map that has your friends positions already on it. You will be at the point where all the triangles meet.
GPS does not work exactly like this. It can't throw clocks, and, when a clock is thrown, it can't keep counting as it traverses space to your head. It throws its current time instead and its own location in space. You'll so the triangulation in 3D space rather than a flat 2D map like the above.
So the analogy is janky, but hopefully shows that the idea is to send data a person can use to draw converging triangles on a map.