html geolocation: Unknown error acquiring position

和自甴很熟 提交于 2019-12-23 12:29:16

问题


I am trying to use HTML geolocation to get my position. Funny thing is, it was working brilliantly until some seemingly random point in the day when it just stopped working. Now all I get is the error callback with a message:

Unknown error acquiring position

This happened on the day I first started to develop the app. It is a web app built in Node/Express. The browser I am using is Firefox v53 64-bit.

Location is allowed, and I have also tried a fix that I found online which involves going to about:config and changing geo.wifi.uri from:

https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_API_KEY%

to

https://www.googleapis.com/geolocation/v1/geolocate?key=test

This did not work for me.

This does however work on my phones Firefox app, but not the Google Chrome app.

Heres an example code snippet:

    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);
    }

The full page: https://github.com/ThriceGood/Spots/blob/master/views/index.html

Can anyone shed some light on this issue?


回答1:


What worked for me was changing geo.wifi.uri to:

https://location.services.mozilla.com/v1/geolocate?key=test

As per this page: navigator.geolocation.getCurrentPosition do not work in Firefox 30.0



来源:https://stackoverflow.com/questions/44773259/html-geolocation-unknown-error-acquiring-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!