navigator.geolocation.getCurrentPosition/watchPosition is not working in android 6.0
<p>Here is my javascript code :</p>

<pre><code>function getLocation() { 
    //navigator.geolocation.getCurrentPosition(getCoor, errorCoor, {maximumAge:60000, timeout:30000, enableHighAccuracy:true});
    var mobile =jQuery.browser.mobile;
    var deviceAgent = navigator.userAgent.toLowerCase();
    var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
    if(mobile){
        watchLocation(function(coords) {
        var latlon = coords.latitude + ',' + coords.longitude;
         //some stuff
      }, function() {
        alert("error");
      });
    } else {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        } else {
            alert("error");
        }
    }
}

function watchLocation(successCallback, errorCallback) { 
    successCallback = successCallback || function(){};
    errorCallback = errorCallback || function(){}; 
    // Try HTML5-spec geolocation.
    var geolocation = navigator.geolocation; 
    if (geolocation) {
        // We have a real geolocation service. 
        try {
          function handleSuccess(position) {
            alert("position:"+position.coords); 
            successCallback(position.coords);
          }  
          geolocation.watchPosition(handleSuccess, errorCallback, {
            enableHighAccuracy: true,
            maximumAge: 5000 // 5 sec.
          }); 
        } catch (err) { 
            errorCallback();
        }
    } else {  
        errorCallback();
    }
}
</code></pre>

<p>I have tried both <code>getCurrentPosition</code> and <code>watchPosition</code>.</p>

<p>It's reaching <code>errorCalback()</code> method when control comes to <code>geolocation.watchPosition</code> line.</p>

<p>I am testing in <code>Motorola G 2nd Gen</code> with <code>Android 6</code> and <code>Google chrome browser</code> and <code>opera mini</code>.</p>

<p><strong>Update 1:</strong> When I put alert in error call back function I got <code>error:1; message:Only Secure origins are allowed(see:</code><a href="https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features" rel="nofollow noreferrer">link</a>).</p>

<pre><code>    navigator.geolocation.getCurrentPosition(showPosition, function(e)
    {  alert(e); //alerts error:1; message:Only Secure origins are allowed(see:  )
       console.error(e);
    })
</code></pre>

<p><strong>Update 2:</strong> With the help from <a href="https://stackoverflow.com/users/1723695/g4s8">g4s8</a> I am able to findout that the error is because of insecure URL. i.e only accessing with <code>http</code> instead of <code>https</code>.But then also I bypassed that in browser by clicking advanced button.But it will prompt for <strong><code>Do you want to allow location</code></strong>, which I don't want..is there any way to access location without prompting it?</p>