您当前的位置: 首页> JavaScript API 通用版 > 类参考

Class:服务类/Geolocation
构造函数
构造函数 描述
Geolocation([options: GeolocationOptions]) 创建Geolocation对象实例。
GeolocationOptions
属性 类型 描述
enableHighAccuracy Boolean 是否使用高精度。 (默认值:true)
timeout Number 超时毫秒数。若在指定时间内未定位成功,返回超时错误信息“TIMEOUT”。 (默认值:30秒)
maximumAge Number 允许返回指定时间内的缓存结果。如果此值为0,则浏览器将立即获取新定位结果。 (默认值:1分钟)
map Map 展现结果的地图实例。当指定此参数后,定位结果的标注均会自动添加到此地图上。
autoViewport Boolean 定位结束后是否自动调整地图视野 (默认开启)。
onLocationComplete Function 定位完成后的回调函数。 参数:results: GeolocationResult
方法
方法 返回值 描述
isSupported() Boolean 判断是否支持浏览器定位
setLocationCompleteCallback (callback:Function) none 设置定位结束后的回调函数。 参数:results: GeolocationResult
getCurrentPosition() none 获取用户当前位置。 (当定位成功时,回调函数的参数为GeolocationResult对象,否则为null。)
watchPosition() Number 监控当前位置。在监控过程中,当前位置发生变化会持续调用回调函数。
clearWatch(watchId:Number) none 取消对当前位置的监控。 (watchId为监控当前位置的侦听句柄,即watchPosition函数的返回值)
enableAutoViewport() none 启用根据结果自动调整地图层级。
disableAutoViewport() none 禁用根据结果自动调整地图层级。
getStatus() Object 返回结果状态。返回对象包含如下属性: errcode:Number,errmsg:String。
GeolocationResult
属性 类型 描述
point Point 定位结果坐标。
kcode String 定位结果坐标的K码
accuracy Number 精度范围,单位:米