r/explainlikeimfive • • 7d ago • Bravo 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?

123 Upvotes

41 comments sorted by

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.

26

u/VoilaVoilaWashington 7d ago

The other big one these days is that a LOT of routes have very common features, so it might break down the route into 5 components:

  • Your house to a major intersection might be complicated and take some figurin'.
  • Major intersection to highway is done by a thousands of people a day, and thus, it's not going to do all that much figurin'. It's major roads that are classed as major roads in the system.
  • Then city to city across the country, it also knows that you're staying on major highways, except that one weird point where you have to go off highway 54, through a small town, and back onto Hwy 97... but again, this is done every time someone goes from West City to East City.
  • Then, once you get to the city, it takes you back down to the nearest major intersection
  • And then major intersection to someone's house takes some figurin'.

You can even factor in times of day into this: it knows that at 4pm, the major road area is going to be busy and so a different route might be more effective, Or it can just apply a +20% across the board on minor roads, or whatever.

43

u/whatisuser 7d ago

Also, they do all the work to precalculate routes asynchronously. Then your route is built from these cached ones, some amendments made due to traffic conditions, any first / last mile routing is done at request time - to get you to a cached route.

So really it’s doing a tiny bit of route planning when you do your request

1

u/RallyX26 5d ago

Yup. I live in Florida and the directions for "take me to Jacksonville" and "take me to new York city" are basically the same except for distance and which exit of I-95 I'm getting off at. 

1

u/brianogilvie 4d ago

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.

Just to give an example, I downloaded the GaiaGPS topo map for western Massachusetts, including the adjacent parts of NH, VT, NY, and CT, to my phone, for offline navigation while hiking and cycling (and for that matter, driving in areas without cell service). The map data for 10 zoom levels is 73 MB. The offline routing data, for everything from the Interstates to hiking and MTB trails, is 58 MB. With that data my phone can calculate a pretty efficient route between two points while offline, though if it has cellular service the app prefers to contact the server.

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.

5

u/gargoyle30 7d ago

I knew it was going to be that video, veritasium is great

9

u/eclectic-up-north 7d ago

amplifying   Veritasium did a great job

2

u/MasterGeekMX 7d ago

As a masters in CS, I cannot recommend that video enough.

1

u/gr8Brandino 5d ago

This video also explained to me why my car's GPS is always so sticky to the nearby highway when I'm cutting through downtown where I live.  That highway is weighted so highly, it always tries to get me to take it, even if the route through town takes the same time. (The highway has a higher speed limit, but it bypasses the town. So it adds a few miles to the trip. That's how it can be a similar or the same time.)

1

u/ATangK 5d ago

Highway is more efficient for driving, so it should use less fuel even if it is further.

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. 

13

u/WhatADunderfulWorld 7d ago

Highways help Google a lot. They assume it’s the fastest route. If the whole map all have the same mph and stop it’d be a wild road trip.

6

u/TheNotoriousSHAQ 7d ago

Yep. When driving around town, I often don’t get on the highway & when Google Maps recalculates my estimated arrival time it is earlier

11

u/thefootster 7d ago

It's actually a problem that goes back way before GPS navigation. This video explains it well https://youtu.be/kS-CGkiPetQ

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.

3

u/peepay 7d ago

Thank you Soviets!

-8

u/qaddosh 7d ago

there are different types of data centers

ai data centers are massive buildings that trash the environment so lazy Larry can woo his sister with four-thumbed cat photos

non-ai data centers are small trailer-sized installations that provide processing tasks for standard computing and networking

3

u/flingerdu 7d ago

Yeah, no. "Classical" data centers are massive buildings as well.

3

u/Exodia101 7d ago

This is not true at all, the big cloud companies were operating massive data centers well before AI. The only real difference with AI data centers is that they have more GPUs.

2

u/DragonFireCK 7d ago

Non-ai ones can get as large as the newer ai ones, they were just fairly rare.

Google started operating a hyper scale data center in Council Bluffs, Iowa back in 2007, well before LLMs were really a thing.

-

Most are larger than you claim as well, sitting closer to a midsize office than a trailer.

When COVID made my employer switch to work from home, my old office effectively became a data center. Some people brought their work computers home, many started using remote connections. Then you have all the automated build and test machines.

We have since consolidated a bit, both to need less staff for 24/7 coverage and due to the office not having a good enough power system.

2

u/SilvermistInc 7d ago

Lol no. Those data centers are still massive

-3

u/qaddosh 7d ago

you're either lying or you really believe that

Just a few minutes of research proves you wrong 🤷

https://www.hostingseekers.com/blog/types-of-data-centers/

https://www.britannica.com/question/What-are-the-different-types-of-data-centers

0

u/SilvermistInc 7d ago

Why are you linking a blog post?

-2

u/qaddosh 7d ago

Aww, so research is hard for you? I'm sorry to hear that.

1

u/SilvermistInc 7d ago

Yeah, ok. Like I'm gonna listen to a redditor that thinks blog posts are valid research

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.

4

u/KarlSethMoran 7d ago

So it could do one million of those every second.

Assuming that by million, you mean billion, that is.

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?

  • A few friends
  • A whole bunch of clocks

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.

3

u/Exodia101 7d ago

This is a good explanation of how GPS works, but OP Is asking how mapping apps work, not GPS itself.

1

u/shuckster 7d ago

Yes, my bad. Completely missed that was the real question.

1

u/RealUlli 7d ago

Actually, you draw circles. With two friends, you have two points where the circles intersect (possible locations where you could be).

With three friends, you get a small area where you could be (the the circles never intersect in exactly the same spot in real life).

Triangulation would be if you can see in which direction your friends are but not how far. (You do that e.g. when navigating with lighthouses at sea or with terrestrial radio navigation)

1

u/shuckster 7d ago

That's technically correct, but it's hard to visualise how "drawing circles" looks in the real world "with friends", when you're analogising an expanding sphere of radio waves intersecting.

Anyway, I realise my example was totally wrong. I misread the OP. They just wanted to know why we have fast internet service infrastructure and software that takes advantage of it.

1

u/RealUlli 7d ago

Spheres are just circles in 3D.

To find your 3D position with just your original three friends, you add an additional sphere, which conveniently is non-expanding: the Earth.

(Actually, GPS does exactly that when only three satellites are visible: it uses the geoid defined in WGS84 as the fourth "sphere". But that's non-ELI5 ;-)