ye-hcj

js获取用户实时地理位置

if(navigator.geolocation) {
    var id = navigator.geolocation.watchPosition(function(position){
        console.log("纬度" + position.coords.latitude + "经度" + position.coords.longitude)
    }, function(err){
        switch(err.code) {
            case err.PERMISSION_DENIED: return "PERMISSION_DENIED";
            case err.POSITION_UNAVAILABLE: return "POSITION_UNAVAILABLE";
            case err.TIMEOUT: return "TIMEOUT";
            default: return "UNKNOWN_ERROR";
        }
    })
    // navigator.geolocation.clearWatch(id); 停止监视
}else {
    console.log("你的浏览器不支持geolocation");
}

分类:

技术点:

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2021-08-15
  • 2021-12-22
  • 2022-01-01
  • 2021-11-23
  • 2021-12-22
  • 2021-08-13
猜你喜欢
  • 2021-12-22
  • 2021-11-06
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
相关资源
相似解决方案