geonb_bernie

'My Location' Widget and iframes

Blog Post created by geonb_bernie on Aug 27, 2019

button icon for 'My Location' widgetWe use Web AppBuilder (WAB) for ArcGIS to publish most of our map viewers.  So far we have been using the hosted version of WAB (not the Developers Edition).  With a little work we can configure WAB to do what we need.  Once we have completed and tested our WAB apps we take the AGOL URL for the app and embed it in an iframe and then place the resulting HTML doc on our own web server. 

 

This allows us to:

  • utilize our own web domain (geonb.snb.ca). 
  • Include our Google Analytics key

To see what I mean visit our latest WAB app and then type <Ctrl> + U to view the page source.  This has worked well for us but today we had a little problem when we launched a WAB app that included the "My Location" widget.  The widget worked fine in all of our testing but when we launched the app this morning our direcotr called us and said the "My Location" widget is not working!  And he was right - it wasn't working.

 

The problem was the iframe.  If you embed a WAB app in an iframe you need to add this to enable geolocation services:

allow="geolocation"

The entire iframe looks like this:

<iframe SRC="https://geonb.maps.arcgis.com/apps/webappviewer/index.html?id=0fdeee6e84ff41b8b4132fb4b597a545" frameborder="0" scrolling="auto" allow="geolocation"></iframe> 

We discovered this by checking the console mesages in Chrome's developer tools where we found this error:

"Geolocation has been disabled in this document by Feature Policy"

Googleing for this error message lead us to the solution.  Good luck with your next WAB app launch.

Outcomes