亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

HTML5 ????

HTML5 ????

HTML5 ????? ???? ??? ???? ? ?????.

??? ?? ??

HTML5 Geolocation API? ???? ??? ??? ?? ? ?????.

? ??? ???? ????? ??? ? ????, ???? ?? ??? ???? ????? ??? ? ????.

???? ??


Internet Explorer 9+, Firefox, Chrome, Safari ? Opera?? ????? ?????.

??: ????? iPhone? ?? GPS? ?? ???? ? ?????.

????? ??? ????? ?????.

if (navigator.geolocation) { 
   //console.log("瀏覽器支持!"); 
   }else { 
      // console.log("瀏覽器不支持!");
 }

navigator.geolocation? ????? ???? ?? ???? ??? ??? ?? ? ?????. ???:

void getCurrentPosition(onSuccess,onError,options);//獲取用戶當(dāng)前位置
int watchCurrentPosition(onSuccess,onError,options);//持續(xù)獲取當(dāng)前用戶位置
void clearWatch(watchId);//watchId 為watchCurrentPosition返回的值//取消監(jiān)控
rrree

?? ? ?? ??

getCurrentPosition() ???? ? ?? ????? ??? ???? ? ?????. ??? ?? ?? ?? ? ??? ??? ?????:

Instance

實(shí)例:
<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8"/>  
    <title>基于瀏覽器的HTML5查找地理位置</title> 
    <!-- 百度API -->
 <script src="http://api.map.baidu.com/api?v=1.2" type="text/javascript"></script>  
  <script>
           function getLocation(){
               var options={
                   enableHighAccuracy:true, 
                   maximumAge:1000
               }
               if(navigator.geolocation){
                   //瀏覽器支持geolocation
                   navigator.geolocation.getCurrentPosition(onSuccess,onError,options);
                   
               }else{
                   //瀏覽器不支持geolocation
               }
           }
           //成功時(shí)
           function onSuccess(position){
               //返回用戶位置
               //經(jīng)度
               var longitude =position.coords.longitude;
               //緯度
               var latitude = position.coords.latitude;
               //使用百度地圖API
               //創(chuàng)建地圖實(shí)例  
               var map =new BMap.Map("container");
               //創(chuàng)建一個(gè)坐標(biāo)
               var point =new BMap.Point(longitude,latitude);
               //地圖初始化,設(shè)置中心點(diǎn)坐標(biāo)和地圖級(jí)別  
               map.centerAndZoom(point,15);
           }
           //失敗時(shí)
           function onError(error){
               switch(error.code){
                   case 1:
                   alert("位置服務(wù)被拒絕");
                   break;
                   case 2:
                   alert("暫時(shí)獲取不到位置信息");
                   break;
                   case 3:
                   alert("獲取信息超時(shí)");
                   break;
                   case 4:
                    alert("未知錯(cuò)誤");
                   break;
               }
           }
           window.onload=getLocation;
   </script>
</head>
<body
   <div id="container" style="width:600px;height:600px"></div>
</body>
</html>


???? ??
||
<!DOCTYPE html> <html> <head>  <meta charset="utf-8">  <title>php中文網(wǎng)(php.cn)</title>  </head> <body> <p id="demo">點(diǎn)擊按鈕獲取您當(dāng)前坐標(biāo)(可能需要比較長的時(shí)間獲?。?lt;/p> <button onclick="getLocation()">點(diǎn)我</button> <script> var x=document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition,showError); } else{x.innerHTML="Geolocation is not supported by this browser.";} } function showPosition(position) { x.innerHTML="緯度: " + position.coords.latitude + "<br>經(jīng)度: " + position.coords.longitude; } function showError(error) { switch(error.code) { case error.PERMISSION_DENIED: x.innerHTML="用戶拒絕對(duì)獲取地理位置的請(qǐng)求。" break; case error.POSITION_UNAVAILABLE: x.innerHTML="位置信息是不可用的。" break; case error.TIMEOUT: x.innerHTML="請(qǐng)求用戶地理位置超時(shí)。" break; case error.UNKNOWN_ERROR: x.innerHTML="未知錯(cuò)誤。" break; } } </script> </body> </html>