html5 navigator.geolocation obtains geographical location code case based on browser

黄舟
Release: 2017-04-01 11:15:10
Original
3388 people have browsed it

1.Introduction

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可以不写,为默认即可
Copy after login

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,//获取地理位置信息时候的时间
Copy after login

3. Example based on googlemap

Look at the code directly :

    在页面上使用google地图示例 
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!