Search code examples
androidgoogle-chromegeolocationmodernizr

Modernizr error when using Chrome on Android devices


I am having an issue that I just noticed and have never seen with my previously released code. In js I am calling

navigator.geolocation.getCurrentPosition()...

I also have coded the success and error portions of the call back. The issue I am having is that on Android devices using Chrome, I am always receiving the error "[object PositionError]"

If I use Firefox on the same device it is fine. All iOS devices I have tested also work.

Has anyone else run into this issue and if so, did you find a solution.

This is my full block of code:

  if (Modernizr.geolocation) {
    navigator.geolocation.getCurrentPosition(
        function (position) {
            var lat = position.coords.latitude;
            var lng = position.coords.longitude;
            callback(lat, lng);
        }
        , function (err) {
            // 1 = PERMISSION_DENIED
            // 2 = POSITION UNAVAILABLE
            // 3 = TIMEOUT
            //if (err.code == err.PERMISSION_DENIED) {
            alert(err);
            alert('Current location could not be obtained from the device.\r\nCheck your GPS settings.');
            //}
        }
        , { timeout: 10000 }//10 secs.
    );
} else {
    alert('This device does not support GPS locations.');
}

Solution

  • As of Chrome 50, you are no longer able to access geolocation APIs from non https web pages.

    Thanks to projects like Lets Encrypt, you can now get an SSL certificate for free, however.