<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="getarea">获取地理位置</div>
<!--
geolocation对象还有2个方法,
1个是watchPosition(success,error,options); 重复获取地理位置
1个是clearWatch()用来清除前一次获取的位置信息
2个方法组合使用可以实现导航功能
Demo请在IE10以上版本测试!
-->
<script>
window.onload=function(){
var getarea=document.getElementById('getarea');
getarea.onclick=function(){
//判断浏览器是否支持对象
if(navigator.geolocation){
//getCurrentPosition支持3个回调函数
//参数1的回调函数获取信息成功的函数
//返回coords.latitude纬度 coords.longitude经度 coords.altitude海拔 coords.accuracy位置精确度
//coords.altitudeAccuracy 位置海拔精确度 coords.heading 方向,正北开始计算 coords.speed 速度米/秒 coords.timestamp 响应的日期
//参数2的回调函数获取信息失败的函数
//code 错误代码 message是错误信息
//参数3的回调函数可以支持按照您的需求来设置一些参数
//enableHighAccuracy表示是否允许使用高精度
//timeout指定超时时间
//maximumAge是指缓存的时间
navigator.geolocation.getCurrentPosition(getsuccess,geterror,getoptions);
}
else{
console.log('浏览器不支持!');
}
function getsuccess(objarea){
console.log('纬度是'+objarea.coords.latitude);
console.log('经度是'+objarea.coords.longitude);
console.log('海拔是'+objarea.coords.altitude);
console.log('位置精确度'+objarea.coords.accuracy);
console.log('海拔位置精确度'+objarea.coords.altitudeAccuracy);
console.log('方向'+objarea.coords.heading);
console.log('速度'+objarea.coords.speed);
console.log('响应时间'+objarea.coords.timestamp);
}
function geterror(objarea){
console.log('错误代码'+objarea.code);
console.log('错误信息'+objarea.message);
}
function getoptions(objarea){
objarea.timeout=1000;
}
}
}
</script>
</body>
</html>苹果手机中禁止非HTTPS协议获取地址位置可以考虑使用微信jdk获取
window.setInterval(method,time)方法本身会返回一个资源句柄,使用clearInterval(Intervalid)方法即可清除定时器<script> var num=0; //每隔1秒再控制台输...
捕捉模式从DOM最顶层一直到最后一层,冒泡正好相反,具体运行以下实例测试.<!DOCTYPE html> <html> <head> <title>捕捉和冒泡</title> <meta charset="...
开发需求如下,商品下单后需要指定送到日期:送达日期为周一 周三 周六 ,如果今天周一,用户选择周一即为下一周周一。代码如下:<html> <head> <meta charset="utf-8"> <title>...
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script type...
代码1:<!--代码开始--> <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script>...
二期项目中生成的简历二维码是使用canvs生成的,微信浏览器中不能识别二维码,只能扫码。懒的换phpqrcode,于是转canvs。//设置一个url var url = "{yun:}$config.sy_weburl{/yun}/mingli/index....