Sebastian
Sebastian

Reputation: 1179

Geolocation Error in Google Chrome

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

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

Upvotes: 10

Views: 11650

Answers (5)

amir marjani
amir marjani

Reputation: 21

As far as I know, this error is related to domain certificate and in Chrome it just works with URLs that start with "Https", not "http".

If you change your browser from Chrome to Edge or something else, this error will not appear.

Upvotes: 0

Cezary Tomczyk
Cezary Tomczyk

Reputation: 584

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.

Upvotes: 2

Sebastian
Sebastian

Reputation: 1179

The problem seems to be solved. I do not change anything. I think it is a corporate proxy problem.

Upvotes: 0

wyqydsyq
wyqydsyq

Reputation: 2020

Everyone in my workplace is currently experiencing this issue on both our own code and the Google Maps API examples.

It seems that periodically Google's network location provider service is unavailable, causing all devices that can't determine location from other means (GPS or Cell tower triangulation) will fail.

Honestly this seems like a really flimsy implementation - why isn't there a fallback network location provider for chrome?

Upvotes: 1

Stiofan O&#39;Connor
Stiofan O&#39;Connor

Reputation: 362

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

Upvotes: 3

Related Questions