<!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获取
离线缓存的开启实例使用apache设置 1.apache配置文件搜索Addtype,我的addtype已经存在项目,如下 AddType application/x-compress .Z AddType application/x-gz...
TmodJS是一套完整的前端模块框架。 虽然我们PHP框架自带各种模板引擎,但是始终是后端模板引擎。例如我们在使用ThinkPHP3.2.3中如果是Ajax异步加载页面,拼接HTML真的是很头疼的一件事情。...
<!DOCTYPE html> <html> <head> <title>捕捉和冒泡</title> <meta charset="utf-8"> </head> <bo...
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script type...
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>获取mac地址</title> </head&g...
通过FormData对象可以组装一组用 XMLHttpRequest发送请求的键/值对。它可以更灵活方便的发送表单数据,因为可以独立于表单使用。如果你把表单的编码类型设置为multipart/form-data ,则通过FormData传输的数据格式和表单通过submit() 方法传输的数据格式相同...