获取用户地理位置关键api:
navigator.geolocation.getCurrentPosition(showPosition,showError,option)
其中三个参数分别表示:
showPosition : 成功的回调
showError : 错误的回调
option:数据获取的方式
showPosition属性
coords.accuracy : 获取位置的精度
coords.altitude : 获取海拔(米)
coords.altitudeAccuracy : 获取位置的海拔精度
coords.heading : 获取方向
coords.latitude : 获取纬度
coords.longitude : 获取经度
coords.speed : 获取速度
timestamp : 获取相应的时间
showError 属性
PERMISSION_DENIED : 用户拒绝页面发起的地理位置
POSITION_UNAVAILAVLE : 无法获取当前位置
TIMEOUT : 超时
option 参数
enableHighAcuracy : 是否启动高精模式(布尔值)
maximumAge : 设置定位缓存过期的时间(毫秒,0为禁用缓存)
timeout : 设置获取定位信息的时常 (超时触发ErrorCallback)
代码如下:

网友评论