html5 navigator.geolocation…
来源:互联网 发布:xml json yaml 编辑:程序博客网 时间:2024/05/21 06:33
一、简介html5为window.navigator提供了geolocation属性,用于获取基于浏览器的当前用户地理位置。window.navigator.geolocation提供了3个方法分别是: voidgetCurrentPosition(onSuccess,onError,options); // 获取用户当前位置 intwatchCurrentPosition(onSuccess,onError,options); // 持续获取当前用户位置 voidc
一、简介
html5为window.navigator提供了geolocation属性,用于获取基于浏览器的当前用户地理位置。
window.navigator.geolocation提供了3个方法分别是:
void getCurrentPosition(onSuccess,onError,options);
//获取用户当前位置
int watchCurrentPosition(onSuccess,onError,options);
//持续获取当前用户位置
void clearWatch(watchId);
//watchId 为watchCurrentPosition返回的值
//取消监控
options = {
enableHighAccuracy,//boolean 是否要求高精度的地理信息
timeout,//获取信息的超时限制
maximumAge//对地理信息进行缓存的时间
}
//options可以不写,为默认即可
当成功获取地理位置信息时候,onsuccess方法中会返回position对象,通过这个对象可以获取地理位置的相关信息,包括:
position对象的属性:
latitude,//纬度
longitude,//经度
altitude,//海拔高度
accuracy,//获取纬度或者经度的精度
altitudeAccurancy,//海拔高度的精度
heading,//设备前景方向。正北方向的顺时针旋转角
speed,//设备的前进速度 m/s
timestamp,//获取地理位置信息时候的时间
三、基于google map的例子
直接看代码:
DOCTYPE HTML>
<</span>html lang="en">
<</span>head>
<</span>meta charset="UTF-8">
<</span>title>在页面上使用google地图示例</</span>title>
</</span>head>
<</span>body onload = 'init()'>
<</span>div id="map" style='width:800px;height:800px;'></</span>div>
<</span>script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false'></</span>script>
<</span>script type="text/javascript">
function init(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(pos){
var coords = pos.coords;
var latlng =new google.maps.LatLng(coords.latitude,coords.longitude);
var options = {zoom:14,center:latlng,mapTypeId : google.maps.MapTypeId.ROADMAP};
var map1;
map1 =new google.maps.Map(document.getElementByIdx_x('map'),options);
var marker =new google.maps.Marker({
position : latlng,
map : map1
});
var infowindow =new google.maps.InfoWindow({
content : '当前位置!'
});
infowindow.open(map1,marker);
});
}
}
</</span>script>
</</span>body>
</</span>html>
0 0
- html5 navigator.geolocation…
- navigator.geolocation
- navigator.geolocation
- html5 geolocation / 百度地图api Geolocation 定位当前城市信息&window.navigator.geolocation.getCurrentPosition,在IO
- navigator.geolocation例子
- js定位navigator.geolocation
- navigator.geolocation API 地理位置
- html5 geolocation
- HTML5 Geolocation
- HTML5 Geolocation
- HTML5 Geolocation
- JS新API标准 地理定位(navigator.geolocation)基于Html5的位置定位
- HTML5全球定位系统Geolocation初探
- HTML5的Geolocation API
- HTML5全球定位系统Geolocation初探
- HTML5之Geolocation API
- HTML5全球定位系统Geolocation初探
- HTML5 Geolocation 地理位置 - 6
- php常用函数整理
- c# try catch finaly用法
- sed命令详解
- Another MySQL daemon&n…
- 设置 viewport 实现定宽…
- html5 navigator.geolocation…
- JS-省市县三级联动
- postgresql常用命令
- css3
- icloud file descrypter
- 即使这么忙,还是要记录下这个AndroidStudio的坑:Binary XML file line #20: You must supply a layout_width attribute.
- 以后的文章会迁移到简书
- Hibernate配置文件详解
- WEBAPI实体参数调用