HTML5定位服务

1.作者

caicongyang:http://blog.csdn.net/caicongyang

2.效果

HTML5定位服务_第1张图片

3.代码

<!DOCTYPE html>
<html>
  <head>
  	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> 
    <title>location.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
    This is my location page. <br>
  </body>
  <script type="text/javascript">
  	 if(supportsGeoLocation()){
        alert("你的浏览器支持 定位.");
     }else{
        alert("你的浏览器不支持 定位");
     }
  	navigator.geolocation.getCurrentPosition(locateSuccess,locateFail);
  	
  	function locateSuccess(pos){
  	  	alert("维度:"+pos.coords.latitude+";经度:"+pos.coords.longitude+";精度:"+pos.coords.accuracy+";当前时间:"+pos.timestamp);
  	}
  	function locateFail(error){
  		switch(error.code){
		case error.PERMISSION_DENIED:
		  alert("用户不允许!");
		  break;
		case error.POSITION_UNAVAILABLE:
		  alert("无法获取定位信息!");
		  break;
		case error.TIMEOUT:
		  alert("定位超时!");
		  break;
		case error.UNKNOWN_ERROR:
		  alert("未知错误!");
		  break;
		} 
	 };
	 
	 //定位监听与移除
	 var watchId = navigator.geolocation.watchPosition(locateSuccess,locateFail);
	 navigator.geolocation.clearWatch(watchId);
	 
  </script>
</html>



你可能感兴趣的:(html5,html5定位,HTML5定位服务)