If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Geolocation

The Internet is global, yet it can help us find the services, products, and events near us. Where's the nearest bank? What restaurants will deliver to me? Which of my friends live in the area? What bus will get me to my destination?
To answer those questions, a program needs to know a user's geolocation: an approximate latitude and longitude describing their geographic location.
A satellite photo of an area with roads, forest, and grasslands, with a marker near a rod.
A geolocation with a latitude and longitude of 39.33673, -87.71237.
Let's review the ways that geolocation can be determined and consider the many ways it can be used.

Device positioning systems

The geolocation of a user is actually the position of a user's device, whether that's a home computer, laptop, smartphone, or fitness tracker.
There are multiple ways for a device to determine its own position in the world, ranging from the most precise (GPS) to the least precise (IP-based geolocation).

Global positioning system (GPS)

The US government started the GPS project in the 1970s and now controls around 30 GPS satellites orbiting the earth. 1
Illustration of earth with 24 GPS satellites in orbits around it.
GPS satellites orbiting the earth. Image source: NOAA
GPS receivers are tiny sensors with antennas that receive radio signals from the GPS satellites orbiting in the sky above. In most cases, if a sensor can receive signals from at least four satellites, the receiver can calculate its position using a technique called trilateration.2
Illustration of GPS receiver interpreting signals from 4 GPS satellites orbiting above it.
GPS works best in an outdoor environment with a clear view of the sky. A smartphone can typically record a geolocation that is accurate to within 4.9 m (16 feet) in open sky. GPS doesn't work as well indoors or near buildings due to the interference caused by roofs, walls, and other objects, but it is still the most precise source of geolocation data.

Wi-Fi positioning system

Wi-Fi positioning is a strategy that works well in dense, urban areas filled with Wi-Fi networks (nearly the opposite of where GPS works well).
First, a device with a Wi-Fi antenna can scan for Wi-Fi access points and measure the signal strength to each network.
That results in information like the table below. Note that signal strength is always negative, so the number closest to zero is strongest.
BSSIDMAC addressSignal strength (RSSI)
NETGEAR09A3:F3:5D:2A:A3:1B-59
NETGEAR09-5GA3:F3:5D:2A:A3:1B-72
Sonic-b34653:19:DA:E0:57:3A-79
EmdutosE3:84:14:BC:BC:FF-84
Baskind Bunch52:8D:5E:29:E7:5A-85
Sonic-9472-5G4C:4C:DB:91:1A:1A-88
xfinitywifiF8:59:F4:FC:C5:F1-93
Once the device has that information, it can use trilateration. The device determines the location of each access point by looking it up in a Wi-Fi location database or in their own (smaller) cache of locations. It then estimates its own location based on the found locations and their signal strength.
A diagram of Wi-Fi trilateration. Three wireless access points are shown with three circles of varying sizes centered on each point. A line goes from the access point in the center to the edge of the circle and is labeled D1, D2, and D3, respectively. There is a small highlighted area in the center where all three circles overlap.
Trilateration based on three access points with different signal strengths. Each circle is an approximated distance based on the signal strength. The device is located in the center area where the three circles overlap.
A more accurate technique is fingerprinting, but it's only possible if a fingerprint map has been made ahead of time. To make the map, a portable device computes the fingerprint for many reference points within a particular area. Each fingerprint is the list of nearby networks and their signal strength, like the table above, plus a pair of geographic coordinates.
A floor plan for the White House second floor, showing long hallways and multiple rooms. Three access points are located in three separate rooms. Many circles, representing fingerprints, fill the halls and rooms.
An imaginary fingerprint map for the White House second floor, with three wireless access points and 46 fingerprints. Image source: ZooFari
When a mobile device enters the area and needs to know its location, it can send its fingerprint to the machine with the radio map, and the machine uses an algorithm to compute the closest fingerprint and estimate the coordinates accordingly.
This technique can be very accurate indoors, especially with a dense fingerprint map, but it's not yet in common use, since it depends on the existence of that fingerprint map.

Cell tower trilateration

In the US, cellular phones are legally required to report their approximate location in the case of 911 calls, to help emergency services get to the callers quickly. If a cell phone is unable to use GPS to report its location, it can instead use cell tower trilateration.
Cell towers are what makes cellular networks possible. Each cell tower includes three sets of directional antenna arrays in a triangular shape:
The top of a cell tower, a triangular structure with antennas.
The cell tower can estimate the distance between the tower and a phone by measuring the round-trip delivery time and signal strength. It can improve that estimate by knowing which of the three antenna arrays sent the signal. A single tower is enough to calculate a wide area, but if multiple towers are available, the location can be narrowed down to a smaller area.
An animation of cell tower trilateration.
Trilateration based on three towers. The highlighted areas represent the antenna on each tower that's sending the signal to the cell phone. The red area in the center is the approximate location of the phone.

IP-based geolocation

Whenever a device sends data over the Internet, it also sends along an IP address. Even though an IP address isn't like a mailing address that describes an unmoving place in the world, it is often possible to map IP addresses to a geographic area.
IP geolocation databases contain millions of rows mapping IP addresses to locations. Companies create those databases based on a variety of sources such as regional IP address registries, user-submitted locations on websites, data from ISPs, and estimates based on network routes.
To give you an idea for the accuracy, I looked up my own IP address in three different IP geolocation databases. The results:
CountryStateCityLatitudeLongitude
USACaliforniaCorona33.8753-117.5664
USACaliforniaRichmond37.9358-122.3478
USACaliforniaSanta Clara37.3541-121.955
The databases all got the country and state correct, and for some purposes, that might be all that's needed. However, the coordinates span a range of 475 miles! 😬
IP-based geolocation is typically the last resort, since it is the most inaccurate of all the techniques. Plus, if a user is accessing the Internet through a VPN (Virtual Private Network), their true IP will be hidden and the VPN's IP could be geolocated in an entirely different continent.

Program access to geolocation

Even when a device has a way to determine its geolocation, it doesn't necessarily expose that information to the software running on it.
Let's look at the various ways that websites and mobile applications can find out the user's location.

Request access

Webpages can use the browser's built-in geolocation API to request the current geolocation. The browser calculates the geolocation using many of the strategies mentioned above and returns the most accurate one.
The browser will first ask the user for permission, however. Here's what that request looks like in the Chrome browser:
Screenshot of web browser URL address bar and pop-up notification. Notification says "m.ymca.net wants to know your location" with buttons for "Block" and "Allow".
Mobile apps also typically must ask for permission for the current geolocation, although that depends on the mobile platform (i.e. Android vs. iPhone). Some apps will even request permission to continually collect the user's geolocation, even while they're not actively using the app.
Here's a request from an app on an Android phone:
A pop-up with the text "Allow Radar to access this device's location?" and three buttons:
  • "Allow all the time"
  • "Allow only while using the app"
  • "Deny"

IP-based geolocation

When a user visits a website, their browser sends an HTTP request to the web server. The HTTP request is wrapped in an IP packet, so it always includes the sender's IP address.
As we described above, the web server can use an IP geolocation service to turn the user's IP address into an approximate location.
IP-based geolocation isn't terribly accurate, but it can at least give a website a clue as to where their users are coming from. The website can use the approximate location to personalize the experience, serve targeted advertisements, or simply understand their user demographics better.

User input

Websites and apps can also simply ask the user for their location.
For example, the user can type in an address and the website can use a geocoding service to convert that into a latitude and longitude.
Here's a store locator that shows the nearest stores for a user's zip code:
Screenshot from ampleharvest.org, with an input field, search box, and map. The input field has the zip code 13078 and the map shows markers around Syracuse, New York.
Websites can also detect the geolocation of user uploaded photos by looking at the metadata of each photo file, since many phones automatically record location inside photo files. Users don't always realize that, so online photo galleries have become a treasure trove of publicly available user locations.

Benefits and risks

Thanks to geolocation, we can find our lost phone, discover a local café to satisfy our craving for a quiche, or document an epic cross-country bike ride. Law enforcement agencies can locate violent offenders, and ambulances can rush to a caller's location.
But geolocation is also private information, and public access to private information always has its risks:
  • There have been multiple cases of people using publicly accessible geolocation data to stalk a former partner or a stranger. 3
  • Law enforcement agencies have been accused of using an inaccurate geolocation to wrongly accuse someone of a crime. 4
  • Websites can choose to censor information based on where they think a user lives.
🤔 What are other negative consequences of allowing our geolocation to be tracked by devices, networks, and programs?

🙋🏽🙋🏻‍♀️🙋🏿‍♂️Do you have any questions about this topic? We'd love to answer—just ask in the questions area below!

Want to join the conversation?

  • aqualine ultimate style avatar for user river harkins
    Can websites sell your location to other companies or websites?
    (17 votes)
    Default Khan Academy avatar avatar for user
    • male robot hal style avatar for user anonymous
      companies or websites, but it depends on various factors, including the website's privacy policy, user consent, and legal regulations.

      Here's how it works:

      User Consent: Some websites request permission to access your location for specific purposes, such as providing localized content or services. When you grant permission, the website may collect and use your location data. However, reputable websites typically use this data for their intended purpose and do not sell it without your explicit consent.

      Third-Party Services: Some websites incorporate third-party services, such as advertising networks or analytics providers. These third parties might have access to your location data if the website shares it with them. In some cases, these third parties could use the data for targeted advertising or other purposes.

      Privacy Policies: Reputable websites have privacy policies that explain how they collect, use, and share your data, including location information. Before using a website, it's a good practice to review its privacy policy to understand how your data is handled.

      Legislation and Regulations: Laws like the General Data Protection Regulation (GDPR) in Europe and the California Consumer Privacy Act (CCPA) in the United States place restrictions on how websites can collect, use, and share personal data, including location information. Websites must comply with these regulations and provide options for users to control their data.

      Opt-Out Options: Some websites offer users the ability to opt out of location tracking or data sharing. This allows users to make informed choices about whether they want their location data to be collected and shared.

      Invasive Practices: Unfortunately, there have been cases of less reputable websites or data brokers that collect and sell users' location data without their explicit consent. These practices are considered invasive and raise serious privacy concerns.

      To protect your privacy:

      Check Permissions: Review the permissions you grant to websites and apps when they request access to your location. Consider whether the requested access aligns with the purpose of the website or app.

      Use Browser Settings: Modern web browsers allow you to control website access to your location. You can choose to allow or block location access for individual websites through browser settings.

      Review Privacy Settings: If a website provides user accounts, check your account settings for privacy options. Many platforms offer settings to control data sharing and ad personalization.

      Stay Informed: Keep up to date with privacy regulations and practices, as they can vary based on your location.

      It's important to be cautious about the websites you use and to make informed decisions about sharing your location data online.
      (8 votes)
  • blobby green style avatar for user Aland Soran
    Why on earth would phones automatically record location inside photo files?
    (7 votes)
    • leaf yellow style avatar for user SP
      It's helpful if you're looking through your pictures, and perhaps you wonder exactly where that picture was taken. It can be helpful if you're at a store and see a product that you like. Or you can just use it to bookmark a location.
      (8 votes)
  • duskpin ultimate style avatar for user Breezy-Horse🌊
    Does geolocation have security protocols?
    (7 votes)
    • stelly blue style avatar for user Evan Lewis
      Yes, there are some security protocols. For example, the article mentions that browsers and mobile devices ask the user for permission before sharing your geolocation with a website or mobile app. However, before sharing your geolocation with a service, you must trust that they will handle that data responsibly.
      (7 votes)
  • blobby green style avatar for user colton.horrell
    its bad because someone could rob you or kidnap you.
    (10 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Kathryn Abernathy
    Geolocation is dangerous in many ways. But we could turn off our GPS on apps. What will happen if in a few years we can't do that?
    (5 votes)
  • primosaur seedling style avatar for user daryn.underwood
    If you call the police, where does your phone send your information(IP address, WiFi address, Geolocation etc)? Can the information get hijacked along the way to its destination? Does it send the information immediately, if at all? Or does the police station have to look for your information?
    (7 votes)
    Default Khan Academy avatar avatar for user
  • old spice man green style avatar for user Josh Jfamily
    when someone is at sea do GPS satilites connect with the ship you are on, or do they communicate with the nearest land conneting point and then the land conecting points communicate with the ships?
    (5 votes)
  • aqualine ultimate style avatar for user Zyan
    Why can they track your Geo location and coordinates of where you live, isn't that private information you are not supposed to tell or show anyone...?
    (8 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user johnson myracle
    Why does it always ask for our location
    (5 votes)
    • area 52 yellow style avatar for user Riley
      Well it depends on the app but there is many reasons why a website or app might ask you for your location.
      Here are some apps/websites and why they ask for your location.

      Weather: With your location, weather apps can accurately give you the forecast for your area.

      Maps & Travel: Navigation apps require your location for turn-by-turn directions, and use your location to help you find cool places nearby. Ride-sharing apps (like Uber and Lyft) also use your location, so drivers know where to pick you up.

      Social Media: Social media apps ask for your location if you want to tag yourself at a cool place.

      Smart Home: Your location is used for geofencing so that devices in your house automatically turn on and off when you leave or get home.

      Shopping: Many retail store apps will ask for your location for simple things, like easily finding a location nearest you.

      Camera: Camera apps can use your location data too, mostly to insert the location into the EXIF data in photos!

      Games: Few games require your location, but some (like Pokémon Go) rely heavily on it.

      Some apps don't even need your location at all but instead use your location to track you and show you targeted ads based on your location history.

      In the end, remember to think about who you want to give your location too. And if an app/website really needs your location or not.
      (3 votes)
  • male robot johnny style avatar for user Killian Mbappe
    Can all websites track you 🤣🤩
    (3 votes)
    Default Khan Academy avatar avatar for user