Fixing the Geolocation Error in most ESRI apps

A work around on solving the Geolocation has been disabled in this document by Feature Policy normally found in embedded ESRI apps.

Fixing the Geolocation Error in most ESRI apps
Photo by Himesh Kumar Behera

Ever tried embedding an application that requires the user's current location but the function to track their location doesn't seem to work?

As an ESRI user, I normally face this issue whenever I try to embed their maps, dashboards, experience builder apps into my own platforms.

You normally get an error like this.

Geolocation restriction error alert

Once you get this on your application then the whole purpose gets defeated. Its game over for you.

Well today, I am here to tell you that it's not the end. There is a workaround this problem which is just one line of code away.

A similar question has been raised on this over the ESRI Community platform. Fortunately enough, I am also a member of this community and got the chance to add my input to the matter.

Peter Klingman reported this to be a bug on the platform. His partial response to the original question;

Looking at the bug linked above (BUG-000129375: Creating a Web AppBuilder application using a Near M.. ) I expect this will be resolved at the end-of-September ArcGIS Online update (8.3, listed as the version fixed in the bug).

I am not sure if the issue has since been resolved, but the workaround method has been working wonders for me.

The Workaround

You might have noticed the default standard to allow geolocation in an embedded application being as simple as adding

allow = "geolocation"

to the attributes of the <iframe>.

Well in a case for ESRI applications, that does not seem to work unfortunaely. unfortunately

The complete solution when it comes to ESRI apps is a simple addition of an asterisk (*) and a semi-colon to the allow geolocation attribute.

In other words, your overall solution should look something like this

<iframe src="<your-app-url>" allow="geolocation *;"></iframe> 

Notice the *;? That's the trick 😉

Problem solved. Now do not give up on embedding those applications and maps.