HTML5 地理位置概述及对象详细说明
1. 地理位置
经度:连接南北两极的线
纬度:连接东西的线 。位置信息来自
IP 地址
GPS 全球定位系统
Wi-Fi 无线网络
基站
3. Geolocation 对象 (❿) 定位对象 (❿) : getCurrentPos化(请求成功、请求失败、数据采集方式)
– 请求成功功能
» 经度:
» 纬度:❀❀ » 准确度: » 高度: 准确度:
» 行驶方向:
» 返回速度:
»时间戳:new Date()
– 请求失败功能
»错误编号:代码 不包含在其他错误编号中 错误
»1:用户拒绝了浏览器获取位置信息
»2:尝试获取用户信息但失败
»3:设置了超时值,位置获取超时
–数据采集:json schema
»enable HighAcuracy :更精确的搜索,默认 false
»timeout:允许获取位置的最长时间,默认无限
»maxtime:最长时间:位置可以被缓存,默认 0
<script>//LBS : 基于地图信息的应用window.onload =function(){
var oInput = ('input1');
var oT = ('t1');
oInput.onclick =function(){
.getCurrentPosition(function(position){
oT.value +='经度:'+ position.+'\n';
oT.value +='纬度 :'+ position.+'\n';
oT.value +='准确度 :'+ position.+'\n'; //就是经度和纬度的准确度,没什么用处 oT.value +='海拔 :'+ position.+'\n';
oT.value +='海拔准确度 :'+ position.Acuracy+'\n';
oT.value +='行进方向 :'+ position.+'\n'; //移动设备上才有用,PC不支持 oT.value +='地面速度 :'+ position.+'\n'; //移动设备上才有用,PC不支持 oT.value +='时间戳:'+new Date()+'\n';
},function(err){
alert( );// // 失败所对应的编号
},{
enableHighAcuracy : true,
timeout : 5000,
maximumAge : 5000//每次请求定位的时候,如果不超过这个设置的时间,那么就不重新请求定位,而是用缓存 });
};
};
</script></head><body><input type="button" value="请求" id="input1"/><br /><textarea id="t1" style="width:400px; height:400px; border:1px #000 solid;"></textarea></body>– 多个定位请求 : watchPosition (as setInterval)
» 对于移动设备很有用,位置更改只会触发
» 频率参数的更新频率: – 关闭更新请求 :clearWatch (asclearInterval)
<script>//LBS : 基于地图信息的应用
window.onload =function(){
var oInput = ('input1');
var oT = ('t1');
var timer =null;
oInput.onclick =function(){
timer = .watchPosition(function(position){ //多次定位请求,返回一个id,通过这个id清除多次定位请求
oT.value +='经度:'+ position.+'\n';
oT.value +='纬度 :'+ position.+'\n';
oT.value +='准确度 :'+ position.+'\n';
oT.value +='海拔 :'+ position.+'\n';
oT.value +='海拔准确度 :'+ position.Acuracy+'\n';
oT.value +='行进方向 :'+ position.+'\n';
oT.value +='地面速度 :'+ position.+'\n';
oT.value +='时间戳:'+new Date()+'\n';
},function(err){
alert( );// 失败所对应的编号 .clearWatch(timer);//通过多次定位请求返回的id关闭更新请求
},{
enableHighAcuracy : true,
timeout : 5000,
maximumAge : 5000,
frequency : 1000//更新的频率(多次定位请求的频率) });
};
};
</script></head><body><input type="button" value="请求" id="input1"/><br /><textarea id="t1" style="width:400px; height:400px; border:1px #000 solid;"></textarea></body> 版权声明
本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。
code前端网