獲取用戶地理位置關(guān)鍵api:
navigator.geolocation.getCurrentPosition(showPosition,showError,option)
其中三個(gè)參數(shù)分別表示:
showPosition : 成功的回調(diào)
showError : 錯(cuò)誤的回調(diào)
option:數(shù)據(jù)獲取的方式
showPosition屬性
coords.accuracy : 獲取位置的精度
coords.altitude : 獲取海拔(米)
coords.altitudeAccuracy : 獲取位置的海拔精度
coords.heading : 獲取方向
coords.latitude : 獲取緯度
coords.longitude : 獲取經(jīng)度
coords.speed : 獲取速度
timestamp : 獲取相應(yīng)的時(shí)間
showError 屬性
PERMISSION_DENIED : 用戶拒絕頁面發(fā)起的地理位置
POSITION_UNAVAILAVLE : 無法獲取當(dāng)前位置
TIMEOUT : 超時(shí)
option 參數(shù)
enableHighAcuracy : 是否啟動(dòng)高精模式(布爾值)
maximumAge : 設(shè)置定位緩存過期的時(shí)間(毫秒,0為禁用緩存)
timeout : 設(shè)置獲取定位信息的時(shí)常 (超時(shí)觸發(fā)ErrorCallback)
代碼如下:
