html5Provides the geolocationattributefor window.navigator, which is used to obtain the current user's geography based on the browser Location.
Window.navigator.geolocation provides 3 methods:
void getCurrentPosition(onSuccess,onError,options); //获取用户当前位置 int watchCurrentPosition(onSuccess,onError,options); //持续获取当前用户位置 void clearWatch(watchId); //watchId 为watchCurrentPosition返回的值 //取消监控 options = { enableHighAccuracy,//boolean 是否要求高精度的地理信息 timeout,//获取信息的超时限制 maximumAge//对地理信息进行缓存的时间 } //options可以不写,为默认即可
2. PositionObject
When the geographical location information is successfully obtained, The position object will be returned in the onsuccess method. Through this object, you can obtain relevant information about the geographical location, including:
position对象的属性: latitude,//纬度 longitude,//经度 altitude,//海拔高度 accuracy,//获取纬度或者经度的精度 altitudeAccurancy,//海拔高度的精度 heading,//设备前景方向。正北方向的顺时针旋转角 speed,//设备的前进速度 m/s timestamp,//获取地理位置信息时候的时间
3. Example based on googlemap
Look at the code directly :
The above is the detailed content of html5 navigator.geolocation obtains geographical location code case based on browser. For more information, please follow other related articles on the PHP Chinese website!