H5标签中 获取位置信息及定位

Document
<script>
    //1.getCurrenPosition()获取当前的位置信息
    //2.watchPosition()  监听位置变化 和1 参数一样
    // 3. clearWatch   清除位置监听
    //getCurrentPosition(s,e,p)
    // success 回调(必须有)
    // error 回调
    // options 参数

    // function success(e){
    //     console.log('success',e);
    // }
    // function error(e){
    //     console.log('error',e);
    // }
    // window.navigator.geolocation.getCurrentPosition(success,error);
    //地址拿不到 没有GPS  -----》googlemap 谷歌地图
    // 返回的显示地理信息
    //latiude 纬度
    //longitude 经度
    // accuracy 定位精确度 ,单位m
    //  altitudeAccuracy 海拔精致度,单位m
    // heading 方向
    // speed 速度
    //
    //https://dew.w3.org/geo/api/spec-source.html#coordinates_interface

    
    //watchPosition()
    // function success(e){
    //     console.log('success',e);
    // }
    // function error(e){
    //     console.log('error',e);
    // }
    // var options ={}
    // window.navigator.geolocation.watchPosition(success,error);
    //位置的监听

    // window.navigator,geolocation.clearWatch()
    //清除地理位置
    //可以用于记步功能;需有gps

    // devicemotion 监听速度变化
    //微信摇一摇
    // var speed =25;
    // var lastTIme = 0;
    // var lastx = 0,lasty =0, lastz =0;
    // // var demo =document.getElementsByTagName('div');
    // window.addEventListener('devicemotion',function(event){
    //     console.log(event);
    //    demo.innerHTML = " acceleration-x"+event.acceleration.x +'<br/> y :'+ event.acceleration.y+'<br/>z:'+event.acceleration.z+
    //     '<br/> accelerationIncludingGravity-x:'+event.accelerationIncludingGravity.x +'<br/> y:'+event.accelerationIncludingGravity.y+'<br/> z:'+event.accelerationIncludingGravity.z;
    //    var x = event.acceleration.x;
    //    var z = event.acceleration.z;
    //    var y = event.acceleration.y;
    //     var nowTime = (new Date().getTime());
    //     if(nowTime -lastTIme > 500){
    //         lastTIme = nowTime;
    //         if(Math.abs(x-lastx)>speed || Math.abs(y - lasty)>speed || Math.abs(z -lastz)>speed){
    //         alert('摇一摇');
    //         lastx =x;
    //         lasty =y;
    //         lastz =z;
    //     }
    //     }
    // })
    //可以打印出所含参数
    //加速度,判断设备的变化  例如:微信摇一摇
    //
     
     window.addEventListener('deviceorientation',function(e){
         demo.innerHTML = 'alpha:'+e.alpha+'<br/>'
     })

</script>

猜你喜欢

转载自blog.csdn.net/qq_40877369/article/details/88702714