navigator.geolocation.getCurrentPosition sometimes works sometimes doesn't

前端 未结 25 2039
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 13:33

So I have a pretty simple bit of JS using the navigator.geolocation.getCurrentPosition jammy.

$(document).ready(function(){
  $(\"#business-locate, #people-l         


        
25条回答
  •  忘掉有多难
    2020-11-22 14:11

    This is already an old question, but all answers didn't solve my problem, so let's add the one I finally found. It smells like a hack (and it is one), but works always in my situation. Hope in your situation too.

    //Dummy one, which will result in a working next statement.
    navigator.geolocation.getCurrentPosition(function () {}, function () {}, {});
    //The working next statement.
    navigator.geolocation.getCurrentPosition(function (position) {
        //Your code here
    }, function (e) {
        //Your error handling here
    }, {
        enableHighAccuracy: true
    });
    

提交回复
热议问题