html5 geolocation 总是说位置不可用
黄舟
黄舟 2017-04-17 15:06:38
0
1
564

<script>

    getLocation();

function getLocation(){
    if (navigator.geolocation){
        navigator.geolocation.getCurrentPosition(showPosition,showError);
    }else{
        alert("浏览器不支持地理定位。");
    }
}
function showError(error){
    switch(error.code) {
        case error.PERMISSION_DENIED:
            alert("定位失败,用户拒绝请求地理定位");
            break;
        case error.POSITION_UNAVAILABLE:
            alert("定位失败,位置信息是不可用");
            break;
        case error.TIMEOUT:
            alert("定位失败,请求获取用户位置超时");
            break;
        case error.UNKNOWN_ERROR:
            alert("定位失败,定位系统失效");
            break;
    }
}
function showPosition(position){
    var lat = position.coords.latitude; //纬度
    var lag = position.coords.longitude; //经度
    alert('纬度:'+lat+',经度:'+lag);
}

</script>

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
左手右手慢动作

I often do this when using Chrome, and some mobile phones also do this. Later, I couldn’t locate it and failed to locate it using IP. You can use Firefox and domestic browsers to debug and see.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template