navigator.geolocation.getCurrentPosition sometimes works sometimes doesn't

前端 未结 25 2028
伪装坚强ぢ
伪装坚强ぢ 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:13

    It might be a good idea to use an IP address geo location service as a fallback method when getCurrentPosition fails. For example with our api https://ip-api.io

    $.getJSON("http://ip-api.io/json/",
        function(result) {
            console.log(result);
        });
    

提交回复
热议问题