Issue Solved: HTML5 Geolocation not working in chrome

If your chrome version is 50, then you’ll encounter that HTML5 Geolocation API is not working. In Chrome version 50, HTML5 Geolocation delivered over HTTP no longer supported by Chrome. The getcurrentposition() and watchposition() are deprecated on insecure origins in Chrome 50.

The web page need to be served over HTTPS for using getcurrentposition() of Geolocation API. For example, web page URL http://codexworld.com (insecure origins) is not allowed to use HTML5 Geolocation API and web page URL https://codexworld.com (secure origins) is allowed to use HTML5 Geolocation API.

To handle the insecure origins issue in chrome, you can use the following JavaScript.

navigator.geolocation.getCurrentPosition(
    function(success) {
        /* Location tracking code */
    },
    function(failure) {
        if(failure.message.indexOf("Only secure origins are allowed") == 0) {
            alert('Only secure origins are allowed by your browser.');
        }
    }
});

1 Comment

  1. Ruhul Said...

Leave a reply

keyboard_double_arrow_up