js獲取用戶實時地理位置


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");
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM