Seb*_*ian 10 google-maps google-chrome geolocation
我知道,这个问题在过去已有报道.
但它在2015年得到了解决.现在它又回到了2017年!
Chrome(版本56.0.2924.87(64位))中出现错误(地理位置错误,代码2):
网址位置提供商位于" 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.');
}
}Run Code Online (Sandbox Code Playgroud)
<button onclick="javascript:locate()">Locate me</button>
<input type="text" id="coords" readonly/>Run Code Online (Sandbox Code Playgroud)
此Google Maps API示例中的问题似乎相同:https://developers.google.com/maps/documentation/javascript/examples/map-geolocation
| 归档时间: |
|
| 查看次数: |
6026 次 |
| 最近记录: |