![A Tour of Web Capabilities](https://static.frontendmasters.com/assets/courses/2023-07-11-device-web-apis/thumb.webp)
Check out a free preview of the full A Tour of Web Capabilities course
The "Location Accuracy" Lesson is part of the full, A Tour of Web Capabilities course featured in this preview video. Here's what you'd learn in this lesson:
Max discusses some caveats with location accuracy on iOS and iPadOS. Users specify whether they want web applications to use precise or imprecise location data. This will apply to all web applications, and there is no API for determining which mode the user selected.
Transcript from the "Location Accuracy" Lesson
[00:00:00]
>> We have to see something else before leaving geolocation, and it has to do with iOS. Since iOS and iPadOS 14, users can decide if they want to share with apps precise or imprecise location. If you have an iPhone, you probably have seen that. When you see the dialog, I'm talking about native apps.
[00:00:24]
When you see the dialog about getting location permission, you can decide if you want precise or imprecise. The problem with web apps is that for the iOS, Safari is one app for all the websites. So, if the user, the first website that they have visited, with geolocation on that phone, if the user has selected imprecise, every website from that moment will get imprecise location.
[00:00:56]
And what's that? It will give you roughly the city, or in big city is the neighborhood. That's all. It will pick a random place there, and there is no API to know in which mode the user is, at least from a web point of view. For imprecise, in my testing, you will typically get the accuracy property between 3000 and 9000, that's meters.
[00:01:25]
So that's around between 2 and 6 miles. So that's a way to know when you look at the property from the results of the call back, if it's on that range, you know we are in the imprecise world. It's smart enough, that system, to work okay with borders.
[00:01:48]
I know, if you are close to the border to Mexico or Canada or between France and Spain, if you are in the French side, it will give you an imprecise location, but in France, okay? So it won't cross borders. So you will get the real country, at least, or the real state or province, okay?
[00:02:09]
In that case, it's good. It's not just a random place around. It will try to keep the same city, at least, okay? Makes sense? And Android 12 has something similar, but the issue is, in the case of progressive web app, is per app, not for Chrome as a whole as with Safari.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops