2017-03-02 312 views
10

我知道,this problem已经在过去被报告过。Google Chrome中的地理位置错误

,但它是在2015年解决了现在又回到2017年!

的误差(Geolocation Position Error, Code 2)出现在浏览器(版本56.0.2924.87(64位)):

网络在 'https://www.googleapis.com/' 的位置信息提供:返回 错误代码403

错误代码2

请注意:Chrome需要使用HTTPS进行地理定位!

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/>

的问题似乎是在这个谷歌地图API的例子一样:https://developers.google.com/maps/documentation/javascript/examples/map-geolocation

+0

解决方案检查我的答案https://stackoverflow.com/questions/32328133/in-new-chrome-44-0-2403-157-geolocations-doesnt-works/45319972#45319972 –

回答

0

这个问题似乎得到解决。我什么都不改变。我认为这是一个公司代理问题。

3

这发生在我身上也花了30个minz试图找到一个解决办法只能再尝试重新启动

+0

一个类似的固定为我工作。我关闭了选项卡并重新打开了它。尽管多个域名无效(在不同的标签上)。这是在MacOS Sierra Chrome的Chrome 58上 –

+0

是的,更新Chrome然后重新启动是唯一的方法。 –

1

大家在我的工作目前正在经历上我们自己的代码和谷歌地图API的例子都这个问题。

似乎周期性的Google的网络位置提供商服务不可用,导致无法通过其他方式(GPS或Cell塔三角测量)确定位置的所有设备都将失败。

老实说,这似乎是一个非常脆弱的实现 - 为什么没有一个回退网络位置提供商铬?