title: Android Webview - navigator.geolocation.getCurrentPosition not working
body: <p>I have a very, very simple scenario and I am running into a very common issue (noted by many StackOverflow users over time).  However, I have tried every proposed solution, and none of them seem to work.  Can somebody please help to resolve this question once and for all?</p>
  
  <p>I am building an Android app (for Android 7, let's assume) which contains a Webview which points to a website that implements very simple geolocation.  (My latest, very stripped down version of the website simply displays the user's latitude and longitude.)</p>
  
  <p>I can view the site fine (and it displays latitude/logitude perfectly) in Chrome.  But when I run the app using Webview, nothing is displayed.</p>
  
  <p>Over the past few days, I have tried seemingly every proposed solution (in MainActivity.java) to this issue, but none of the solutions seem to work.</p>
  
  <p>I have added all permissions imaginable in AndroidManifest.xml.</p>
  
  <p>What does one need to do to get this to work?</p>
  
  <p>Surely, viewing a website with geolocation in an Android app with Webview should be fairly straightforward, right???</p>
  
  <p><strong>Edit:</strong>  I've narrowed things down a bit.  I've prompted the user for permissions at runtime, and I've confirmed that geolocation is being allowed.  I've also confirmed that Javascript, in general, is being allowed by my app.</p>
  
  <p>The key/core remaining issue seems to be this:
  The following does <strong>not</strong> appear to work in Webview.</p>
  
  <pre><code>navigator.geolocation.getCurrentPosition(success, error);
  </code></pre>
  
  <p>I don't know why, but that is the problem.</p>
  
  <p>Ref:</p>
  
  <p><a href="https://stackoverflow.com/questions/49920241/android-webview-error-when-asking-for-geolocation">Android webview error when asking for geolocation</a></p>
  
  <p><a href="https://stackoverflow.com/questions/39064165/the-application-does-not-have-sufficient-geolocation-permissions">The application does not have sufficient geolocation permissions</a></p>
  
  <p><a href="https://stackoverflow.com/questions/34986413/location-is-accessed-in-chrome-doesnt-work-in-webview">Location is accessed in Chrome, doesn&#39;t work in WebView</a></p>
  
  <p><a href="https://stackoverflow.com/questions/23498523/android-ask-for-permission-to-use-location-within-webview">Android Ask for permission to use location within webview</a></p>
  
  <p>Minimal geolocation webpage:
  (How to get this to display in Android Webview?)</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset=utf-8 /&gt;
  &lt;title&gt;Webview Test&lt;/title&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id='output'&gt;&lt;/div&gt;
  
  &lt;script&gt;
  
  function success(pos) {
  
    var latitude = pos.coords.latitude;
    var longitude = pos.coords.longitude;
  
    document.getElementById('output').innerHTML = `Your current position is:  Latitude : ${latitude} Longitude: ${longitude}`;
  }
  
  function error(err) {
    console.warn('ERROR(${err.code}): ${err.message}');
  }
  
  navigator.geolocation.getCurrentPosition(success, error);
  
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>