js獲取用戶實時地理位置
阿新 • • 發佈:2019-02-05
console navig avi lse mission watch func var ati
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"); }
js獲取用戶實時地理位置