我正在尝试使用HTML地理位置来获取我的位置。有趣的是,它工作得非常出色,直到它刚停止工作的那一天看似随机的一点。现在我得到的是带有消息的错误回调:
Unknown error acquiring position
这发生在我第一次开始开发应用程序的那天。它是一个内置Node / Express的Web应用程序。我使用的浏览器是Firefox v53 64位。
位置是允许的,我也尝试了一个我在网上找到的修复程序,其中涉及到:配置和更改geo.wifi.uri
:
https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_API_KEY%
到
https://www.googleapis.com/geolocation/v1/geolocate?key=test
这对我不起作用。
但这适用于我的手机Firefox应用,但不适用于Google Chrome应用。
下面是一个示例代码段:
const geo = navigator.geolocation;
geo.getCurrentPosition(success, failure);
function success(position) {
lat = position.coords.latitude;
lng = position.coords.longitude;
$('#coords').val(lat + ',' + lng);
mapView.setCenter(ol.proj.fromLonLat([lng, lat]));
}
function failure(error) {
console.log(error.message);
}
整页:https://github.com/ThriceGood/Spots/blob/master/views/index.html
有人能解释一下这个问题吗?
答案 0 :(得分:3)
对我有用的是将geo.wifi.uri
更改为:
https://location.services.mozilla.com/v1/geolocate?key=test
根据此页面:navigator.geolocation.getCurrentPosition do not work in Firefox 30.0