亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于h5 ajax實現(xiàn)手機(jī)定位(demo)

 更新時間:2015年09月25日 10:47:32   投稿:mrr  
最近沒有項目做,正有朋友請幫忙實現(xiàn)手機(jī)定位功能,實現(xiàn)方法有很多種,我是用h5和ajax實現(xiàn)的手機(jī)定位,只是個demo,后續(xù)還要繼續(xù)完善的,在此分享給大家,需要的朋友可以參考下

因朋友需要,之前看了下關(guān)于h5的手機(jī)定位,目前寫了個demo在這里貼出來,感興趣的朋友可以看一下。

目前的版本只是demo,仍有幾個問題需要完善一下,問題如下:

1,如何將經(jīng)緯度等數(shù)據(jù)發(fā)送到被定位人看不到的頁面上。

2,如何繞過或或強(qiáng)制讓打開鏈接的人允許使用定位(彈窗)。

3,目前或取經(jīng)緯度后,要自行用谷歌地球去分析用戶位置(通過衛(wèi)星地圖定位并顯示),如何簡化這一部分,讓被定位者的經(jīng)緯度自動生成地圖圖片并一起導(dǎo)入到其他頁面(總之不能讓被定位者察覺自己被定位的這一事實)。

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-">
<meta name="viewport" content="width=device-width, initial-scale=, maximum-scale=">
<title>demo..</title>
<script type="text/javascript" src="http://libs.useso.com/js/jquery/../jquery.min.js"></script>
<style type="text/css">
.demo{width:px; margin:px auto px auto}
.geo{margin-top:px}
.demo p{line-height:px; font-size:px}
.demo p span,#baidu_geo,#google_geo{font-weight:bold}
</style>
</head>
<body>
<div id="main">
 <div class="demo">
  <p>地理坐標(biāo):<span id="latlon"></span></p>
  <div class="geo">
   <p>百度地圖定位位置:</p>
   <p id="baidu_geo"></p>
  </div>
  <div class="geo">
   <p>GOOGLE地圖定位位置:</p>
   <p id="google_geo"></p>
  </div>
 </div>
</div>
<script>
function getLocation(){
 if (navigator.geolocation){
  navigator.geolocation.getCurrentPosition(showPosition,showError);
 }else{
  alert("瀏覽器不支持地理定位。");
 }
}
function showPosition(position){
 $("#latlon").html("<br />緯度:"+position.coords.latitude +'<br />經(jīng)度:'+ position.coords.longitude);
 var latlon = position.coords.latitude+','+position.coords.longitude;
 //baidu
 var url = "http://api.map.baidu.com/geocoder/v/?ak=Cbdaebdbbbabceb&callback=renderReverse&location="+latlon+"&output=json&pois=";
 $.ajax({ 
  type: "GET", 
  dataType: "jsonp", 
  url: url,
  beforeSend: function(){
   $("#baidu_geo").html('正在定位...');
  },
  success: function (json) { 
   if(json.status==){
    $("#baidu_geo").html(json.result.formatted_address);
   }
  },
  error: function (XMLHttpRequest, textStatus, errorThrown) { 
   $("#baidu_geo").html(latlon+"地址位置獲取失敗"); 
  }
 });
 //google
 var url = 'http://maps.google.cn/maps/api/geocode/json?latlng='+latlon+'&language=CN';
 $.ajax({ 
  type: "GET",
  url: url, 
  beforeSend: function(){
   $("#google_geo").html('正在定位...');
  },
  success: function (json) { 
   if(json.status=='OK'){
    var results = json.results;
    $.each(results,function(index,array){
     if(index==){
     $("#google_geo").html(array['formatted_address']);
     }
    });
   }
  },
  error: function (XMLHttpRequest, textStatus, errorThrown) { 
   $("#google_geo").html(latlon+"地址位置獲取失敗"); 
  } 
 });
}
function showError(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("定位失敗,定位系統(tǒng)失效");
   break;
 }
}
getLocation();
</script>
</body>
</html>

以上代碼就是實現(xiàn)h5和ajax手機(jī)定位代碼,后續(xù)還會持續(xù)更新完善,請大家持續(xù)關(guān)注腳本之家網(wǎng)站。

相關(guān)文章

最新評論