Day 11: web app vs native app on location services
Tags: googlemaps, geolocation, webapp, webdev
Published: 2021-10-19 11:53:03

## TL;DR

With a web app, the user will be asked for granting permission to use their location information *every time* they access the app. Consequently, showing the user’s current location immediately after accessing the web app will force the user to give permission every time they start using the app. That’s not a pleasant user experience.

## Introduction

This article is the 11th instalment of *100 Days in Kyoto to Create a Web App with Google Maps API*, recording my journey to create *My Ideal Map App* to improve the user experience of Google Maps.

I’ve started working on a feature that shows the user’s current location on embedded Google Maps. But my initial plan on how to implement this feature has to be scrapped due to the limitations of web apps when it comes to location services.

## Initial plan

Initially, I wanted *My Ideal Map App* to show the user's current location immediately after the user accesses the app (or taps the app's shortcut icon if they have added the app to the home screen). 

To build a web app that makes use of location information, we need to use *Geolocation API*. After figuring out how it works by reading [MDN Contributors (2021a)](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API/Using_the_Geolocation_API) and [Kinlan (2019)](https://developers.google.com/web/fundamentals/native-hardware/user-location/), I realized my initial plan wouldn't work.

NOTE: Google Maps Platform offers its own "[Geolocation API](https://developers.google.com/maps/documentation/geolocation/overview)", but it's not for free of charge. It costs $0.005 per request (source: [Google Maps Platform documentation](https://developers.google.com/maps/billing/gmp-billing#geolocation)).

### It would work with a native app

Showing the user's current location by default is what Google Maps iOS app does (and I suppose its Android app as well). 

The first time the user launches Google Maps, they will be asked if they want to allow Google Maps to use their location:

![The iOS app version of Google Maps pops up the modal window that reads "Allow Google maps to use your location?" and offers three choices, "Allow Once", "Allow While Using App", and "Don't Allow"](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zb6hiykw7pcj0mbd3esl.png)

**Google Maps iOS app asks the user for permission to user their location** (screenshot by the author)

If they choose "Allow While Using App", then this choice will be remembered for the future use. Next time the user launches Google Maps, they won't be asked for permission again. The user's current location is immediately shown on the map. 

I like this feature, especially when I'm out in the city. I can immediately see what's around me. When I don't care about my current location, I can just immediately tap, say, the search box at the top of the screen without any obstruction.

With a native app, showing the user's current location by default provides a nice user experience.

### With web apps, it's a different story...

However, as far as I can tell, this nice user experience is not feasible with a web app. Why? Because the user's preference on location services for a particular website won't be saved for the future use. Every time the user launches the app (by typing its URL on the browser or by tapping its shortcut icon on the home screen), they will be asked for permission. 

This is a very annoying user experience. The user doesn't always want to know their current location. They may have launched the app for searching a place or for editing their saved places (which is one of the core features of _My Ideal Map App_). In these cases, it's not pleasant to be obstructed from doing so with a modal pop up message asking for permission on a feature that the user doesn't need at the moment.

Even worse is that, unlike native apps, the pop-up message cannot be customized. For iOS Safari, it'll be a generic message like this:

![The web app version of Google Maps pops up the modal window that reads "The website google.co.jp would like to use your current location" and offers two choices, "Don't Allow" and "Allow"](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sagg0z8ggeb8ofqdr9hp.PNG)

**The web app version of Google Maps asks the user for permission to user their location** (screenshot by the author)

With such a generic message, the user cannot tell why they may want to enable location services for the web app. This is a bad user experience. [Kinlan (2019)](https://developers.google.com/web/fundamentals/native-hardware/user-location/#ask_permission_responsibly) reports:

> Recent user studies have shown that users are distrustful of sites that simply prompt the user to give away their position on page load. 

So [Kinlan (2019)](https://developers.google.com/web/fundamentals/native-hardware/user-location/#always_request_access_to_location_on_a_user_gesture) recommends asking for location service permission _on a user gesture_:

> Make sure that users understand why you’re asking for their location, and what the benefit to them will be. ... [G]ive the user a clear call to action or an indication that an operation will require access to their location. The user can then more easily associate the system prompt for access with the action just initiated.

## Plan B

Consequently, for _My Ideal Map App_, I gave up creating a user experience like Google Maps iOS app offers. Instead, to the screen the user sees immediately after they launch the app, I'll add a button to show the user's location. Tapping this button for the first time will pop up the permission dialog. But as long as the user doesn't close the app, the user's preference on location services will be remembered.

Incidentally, this is exactly what the web app version of Google Maps does. It won't show the user's location by default. Instead, its initial UI contains a button labelled "Your location" which is to show the user's location. Tapping it for the first time will prompt a permission dialog shown above.

![The web app version of Google Maps shows a map with a button labeled "Your location"](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uzb4b2r4c5rnf6opdlgx.PNG)

**Initial UI of the web app version of Google Maps** (screenshot by the author)

## Two more geolocation features unavailable for web apps

As I continue building the geolocation feature for _My Ideal Map App_, I learn that there are a couple of other things that native apps can do but web apps cannot. 

One example is to show the direction the user is currently facing. Google Maps iOS app can show the direction at which the user's iPhone is pointing. With a web app, this is not possible if the user isn't moving. Geolocation API returns no direction information if the user's moving speed is zero ([MDN Contributors 2021b](https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates/heading)).

Another example is *background geolocation* by which the native app can keep track of the user's location even when the screen is off. This feature is unnecessary for _My Ideal Map App_, but it is essential for recording the user's cycling route, for example. On the web, background geolocation is not available due to security reasons ([Yasskin 2021](https://twitter.com/jyasskin/status/1442543204411142151?s=20)). 

Without background geolocation, Google Maps cannot offer its “turn-by-turn navigation”, which is why the web app version of Google Maps keeps popping up the “get-the-app” banner ([Steiner 2021](https://twitter.com/tomayac/status/1442363411409604608?s=20); [Yasskin 2021](https://twitter.com/jyasskin/status/1442543204411142151?s=20)):

![The web app version of Google Maps pops up the modal window that reads "Upgrade to a smarter Google Maps" and offers two choices, "STAY ON WEB" and "CONTINUE"](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sx7hnd8mq56i1qnc40zu.PNG)

**The "get the app" banner by [Google Maps web app](https://www.google.co.jp/maps)** (screenshot by the author)

## Why web app then?

For _My Ideal Map App_, however, it is more important for any device users to get access to the app. I'm sympathetic with [Marcotte (2021)](https://ethanmarcotte.com/wrote/locus/), who laments a recent trend in which many web apps put a banner to encourage the user to download their native app versions. He makes an interesting analogy between native apps and mobile-only websites during the days before *responsive web design* took off:

> When [responsive design first became a thing](https://ethanmarcotte.com/wrote/responsive-design-at-10/), mobile websites were peppered with links to “the full website”…which invariably contained the content or features you *actually* wanted to access on your mobile device. In practice, this encouraged  product teams to adopt device-specific design methods: features weren’t deployed to *people*, but to *specific types of devices*.
>
> By and large, these app prompts feel like fancier versions of that old pattern. And when new product features are built on the native  experience, I think it’s illuminating when they don’t make it back to the web.

I want to deploy _My Ideal Map App_ to people, not to specific types of devices.

## Changelog
**Oct 29, 2021 (v1.1.0)**: Add a paragraph on Google Maps Platform's own Geolocation API.

## References

Kinlan, Paul (2019) “[User Location](https://developers.google.com/web/fundamentals/native-hardware/user-location/)”, _Web Fundamentals_, Feb 12, 2019.

Marcotte, Ethan (2021) “[Locus](https://ethanmarcotte.com/wrote/locus/)”, _ethanmarcotte.com_, Sep 28, 2021.

MDN Contributors (2021a) “[Using the Geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API/Using_the_Geolocation_API)”, _MDN Web Docs_, Oct 11, 2021 (last updated).

MDN Contributors (2021b) “[GeolocationCoordinates.heading](https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates/heading)”, _MDN Web Docs_, Sep 15, 2021 (last updated).

Steiner, Thomas (2021) “[The first point makes it pretty clear: turn-by-turn navigation needs background geolocation...](https://twitter.com/tomayac/status/1442363411409604608)”, _Twitter_, Sep 27, 2021.

Yasskin, Jeffrey (2021) “[There's no excuse for Gmail, but Maps actually can't do turn-by-turn navigation using the web APIs we've thought are safe enough...](https://twitter.com/jyasskin/status/1442543204411142151?s=20)”, _Twitter_, Sep 28, 2021.