When it works, automatic HTML5 geolocation is a wonderful feature which allows your web browser to inform the web server whose web page that you are browsing where you are so it can provide locally relevant content to you. However, there are a large number of factors that this feature is dependent on, from technological, geographical and even to physical which will influence how accurate this feature is in the real world.
Our locator services and those of others leverage this feature because it allows our store locator software to immediately show the closest location to the visitor without them having to enter their address. "When it works" is the key phrase in my opening statement as there's a multitude of possible reasons why browser geolocation can be wildly inaccurate and this can cause some major issues.
Let's get started by looking at the information sources that your web browser will use to find your location. These are in order of accuracy from most accurate to least accurate:
1. GPS (Global Positioning System)
This is available for any device which has GPS capabilities which includes almost every smartphone manufactured in the last 10 years. Accuracy is excellent - typically a smartphone GPS chip can establish your location anywhere on earth within 3 metres 95% of the time.
To do this your phone needs to receive a signal from at least 4 of the 6 satellites that are visible at any point on the Earth's surface. You might get less accurate results if your smartphone can only see 3 satellites because in that scenario the GPS receiver can still get an approximate position by making the assumption that you are at sea level. If you really are at sea level, the position will be reasonably accurate (within 10 metres or so). However if you are at altitude or in the mountains, the 2-D fix could be hundreds of metres off as a result of this approximation.
GPS information is also cached on your smartphone so even if it is unable to receive a GPS signal (for example, you are underground) it will have access to recent GPS data and will use that information as a best guess.
What could make this inaccurate: For GPS to be most accurate, the device in question needs a clear and uninterrupted view of the sky. GPS’s listen for a very weak signal from multiple satellites and these signals can be partially or completely blocked by mountains, buildings, trees or even vehicle roofs.
2. WiFi Positioning System
The way this works is that all the major geolocation service providers (Google, Apple, Microsoft etc) are continuously gathering huge amounts of data on public and private WiFi endpoints and network identifiers (SSIDs). For example, Google's Streetview vehicles gather WiFi signals and their location as they travel along each road and your smartphone regularly sends WiFi network and location data to Google and Apple's servers.
In fact, every time you use a map service on your GPS enabled phone, it picks up the nearby WiFi (and Bluetooth) signals and records that information alongside your GPS position, and sends it to Google or Apple depending on your device. The resulting databases are extremely valuable and are also used to more accurately locate devices that do have GPS, since GPS is slow, does not work indoors or underground and can fail when there are high buildings or mountains nearby or you are in a metal structure.
Accuracy varies but is typically within 5-15 metres. Vendors such as Combain (https://combain.com/about/about-positioning/wi-fi-positioning/) are also proposing making floor level WiFi positioning accuracy within a building, something that GPS cannot deliver.
Let's use an example of how this works in practice:
You have full GPS access and your Wi-Fi is turned on in a grocery store. The location of the store is easily spotted because your GPS is working, so your location and some information about any nearby Wi-Fi networks are sent to the vendor (like Google or Apple).
Later, someone else enters the grocery store with Wi-Fi on but no GPS signal since there's a storm outside, or maybe the phone's GPS just doesn't work well.
Either way, the GPS signal is too weak to determine the location. However, since the location of nearby networks is known (since your phone sent that information in), the location can still be gathered even though GPS isn't working. The beauty of this is that it's public data and it's faster than GPS.
What about another scenario? Say I have a laptop and a smartphone and I am working at home. My smartphone has accurate GPS data on where it is and communicates this with any visible WiFi networks including my unique home network SSID to Google's servers. When my laptop asks for it's location, Google can quickly cross-reference my laptop's WiFi network with the information it previously recorded about my smartphone's location to give my laptop an extremely accurate location within my house.
What could make this inaccurate: If there are no WiFi networks nearby or they haven't been mapped by Google / Apple / Microsoft then this won't work at all. Alternatively, the data could simply be out of date.
3. Mobile Network Location
Mobile phone tracking is normally used when GPS and WiFi positioning aren't available. For example, if you are using a smartphone but the satellite signal is blocked (e.g. you're underground or inside lift shaft or a building that blocks GPS signals due to structural concrete reinforcing) AND there is no cached GPS location data available on the device and there is no WiFi signal. More likely though, we'd be talking about using a device with a cell network connection but without a GPS chip such as an iPad or a laptop with an internal or external 4G cellphone SIM and that is out of WiFi range.
The way this works is like a 2 dimensional version of GPS (or GPS with 3 satellites where the assumption is that you are at sea level). Using cell tower ID triangulation with at least 3 towers, it is possible to determine a phone location to within an area of about 3/4 of a square mile.
What could make this inaccurate: The accuracy goes down as cell towers get further apart so if you are in the country, expect less accurate results. In a city though with lots of cell towers that are close together this is going to give you that sort of accuracy. Also if your phone can see less than 3 cell towers then it's going to be more guesswork and less accuracy.
4. IP Geolocation
The final method used is IP based Geolocation. Here, your location is detected based on the public IP address of your device. As this is typically the most inaccurate positioning method and hence used as a last resort, in this scenario we are typically talking about a desktop computer with a wired only connection to the internet.
Your position is determined based on databases of lookup tables which map IP addresses to locations. The accuracy is typically based on a database which will only return location data accurate to a City or an area within a City. At its most precise though, an IP address can be mapped to a house.
What could make this inaccurate: In many cases your IP is hidden behind Internet Service Provider NAT (Network Address Translation) and the accuracy is only to the level of a city, region or in a worst case scenario, a country. Also, if you are using a VPN (or TOR) then your IP address will be the VPN endpoint at wherever you are tunnelling to which could be halfway around the planet.
At it's least precise, your IP address can be mapped only to a country. In order to deal with that imprecision, geolocation services providers such as MaxMind decided to set default locations at the city, state and country level for when it knows only roughly where the IP address lives. If it knows only that an IP address is somewhere in the U.S., and can't figure out anything more about where it is, it will point to the center of the country. As any geography nerd knows, the precise center of the United States is in northern Kansas, near the Nebraska border and if your location can't be determined by MaxMind, it will spit out the default location of a spot two hours away from the geographic center of the country which is in Wichita, Kansas.
Which location service does each browser use?
Not all Geolocation services are created equal, and they certainly don’t all use the same algorithms and / or use the exact same databases as they are all proprietary. Because of this, the results typically vary across browsers that use different Geolocation services:
- Chrome uses the Google Maps Geolocation API
- Firefox uses the Google Maps Geolocation API
- Safari and all iOS devices use Apple Location Services
- Internet Explorer 9+ use Windows Location Services
What's needed for HTML5 Browser Geolocation to work
Even if all the stars align and you have a GPS capable smartphone which has a perfect view of 6 GPS satellites and so it can locate you down to within 3 metres, a particular web page may still not be allowed to use the HTML 5 Geolocation API to access that location data. Here's a list of potential reasons why:
1. All major web browsers (Chrome, Safari, Firefox, IE, Edge) now ask permission on a per web page basis before they will share your location with a web server. If the user does not permit this data to be shared, then HTML 5 geolocation will fail. It is possible (if the website is coded well) for geolocation to fail back to IP Geolocation as this information is available to the web server when you request a web page but this is the least accurate location mechanism. In practice, most websites don't do this (although note that our Store Locator Software does have this capability!).
Here's a typical prompt:
And if access is Blocked, the notification bar will show something like this:
2. Again, all major web browsers (Chrome, Safari, Firefox, IE, Edge) block HTML 5 geolocation on insecure web pages. This means any web page where the connection is not secured and encrypted using an SSL certificate and accessed via HTTPS instead of HTTP. As above, this means all the juicy accurate geolocation mechanisms will be blocked leaving us to fail back to IP Geolocation if available.
3. If the web page is served over HTTPS as in (2) above, HTML 5 geolocation can STILL be blocked if the web page contains mixed content. Specifically this means content such as images, scripts, CSS files are served over HTTP instead of HTTPS. So, just one HTTP reference to a dependent file can scupper accurate geolocation. Here's how the Chrome error console would look in this scenario:
That's all for now folks. If you'd like to try HTML5 Geolocation out you can try to map your own location here: https://html5demos.com/geo.