Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geolocation Error in Google Chrome

I know, this problem has already been reported in the past.

  • Chrome navigator.geolocation.getCurrentPosition() error 403
  • navigator.geolocation.getCurrentPosition always fail in chrome and firefox
  • Network location provider at 'https://www.googleapis.com/' : Returned error code 403 in Webapp

But it was solved in 2015. Now it's back in 2017!

The Error (Geolocation Position Error, Code 2) appears in Chrome (Version 56.0.2924.87 (64-bit)):

Network location provider at 'https://www.googleapis.com/' : Returned error code 403.

Error Code 2

Please Note: Chrome needs HTTPS for Geolocation!

function getCoords() {
  return new Promise(function(resolve, reject) {
    if (navigator.permissions) {
      navigator.permissions.query({
        name: 'geolocation'
      }).then(function(permission) {
        switch (permission.state) {
          case 'granted':
            navigator.geolocation.getCurrentPosition(function(pos) {
              resolve(pos.coords);
            }, function(error) {
              console.error('Error Code: ' + error.code + ' - ' + error.message);
            });
            break;
          case 'prompt':
            console.info('Check Geolocation Promt.');
            navigator.geolocation.getCurrentPosition(function(pos) {
              resolve(pos.coords);
            }, function(error) {
              console.error('Error Code: ' + error.code + ' - ' + error.message);
            });
            break;
          case 'denied':
          default:
            resolve(null);
            break;
        }
      });
    } else {
      reject(new DOMError('NotImplemented', 'Permission API is not supported'));
    }
  });
}

function locate() {
  if (typeof Promise !== "undefined" && Promise.toString().indexOf("[native code]") !== -1) {
    getCoords().then(function(coords) {
      if (coords !== null) {
        console.log(coords);
        document.getElementById('coords').value = coords.latitude + ', ' + coords.longitude;
      } else {
        console.warn('No coords returned :/');
      }
    });
  } else {
    console.warn('This browser doesn\'t support geolocation.');
  }
}
<button onclick="javascript:locate()">Locate me</button>
<input type="text" id="coords" readonly/>

The problem seems to be the same in this Google Maps API example: https://developers.google.com/maps/documentation/javascript/examples/map-geolocation

like image 406
Sebastian Avatar asked Mar 02 '17 08:03

Sebastian


2 Answers

I know the subject contains Google Chrome, but this error:

Network location provider at 'https://www.googleapis.com/' : No response received.

happens also on Chromium, version 70.0.3538.67 (Developer Build) (64-bit) (macOS, High Sierra).

Maybe this https://bugs.chromium.org/p/chromium/issues/detail?id=820945&can=2&start=0&num=100&q=geolocation&colspec=ID is related.

like image 130
Cezary Tomczyk Avatar answered Oct 15 '22 20:10

Cezary Tomczyk


This happened to me too, spent 30 minz trying to find a solution only to then try restarting

like image 3
Stiofan O'Connor Avatar answered Oct 15 '22 21:10

Stiofan O'Connor