一. 地理定位
地理定位允许用户向web提供他们的位置,基于隐私的考虑,报告地理位置之后需要用户授权.
地理定位需要通过navigator对象的geolocation属性实现,该属性将返回Geolocation对象。 --navigator.geolocation
方法
getCurrentPosition() 用于获取当前的位置,其语法结构是:
Geolocation.getCurrentPosition(success,error,options) //可以带三个参数,必须有得是success
success,指成功获取位置信息后的回调函数,使用GeolocationPosition对象作为唯一参数
error,指获取位置失败时的回调函数
options表示对当前地理定位的配置,为object类型,包含的属性有:
{
timeout:多长时间内返回地理定位(毫秒),
maximumAge:在多长时间内去缓存获取地理定位(毫秒)
}
watchPostion() 用于注册监听器,以监听位置的变化,其语法结构是:
Geolocation.watchPostion(success[,error[,options]])
clearWatch() 取消已注册的监听器,其语法结构是:
Geolocation.clearWatch(id)
GeolocationPosition对象表示当前的位置对象:
timestamp 表示获取地理定位时的时间戳,其语法结构是:
GeolocationPosition.timestamp
coords 将返回GeolocationCoordinates对象,其语法结构是:
GeolocationCoordinates GeolocationPosition.coords
longitude
longitude属性表示经度