亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    html5 navigator.geolocation基于瀏覽器獲取地理位置代碼案例

    一、簡介

    html5為window.navigator提供了geolocation屬性,用于獲取基于瀏覽器的當(dāng)前用戶地理位置。

    window.navigator.geolocation提供了3個方法分別是:

    void getCurrentPosition(onSuccess,onError,options);  //獲取用戶當(dāng)前位置    int watchCurrentPosition(onSuccess,onError,options);  //持續(xù)獲取當(dāng)前用戶位置    void clearWatch(watchId);  //watchId 為watchCurrentPosition返回的值  //取消監(jiān)控      options = {       enableHighAccuracy,//boolean 是否要求高精度的地理信息       timeout,//獲取信息的超時限制       maximumAge//對地理信息進(jìn)行緩存的時間  }  //options可以不寫,為默認(rèn)即可

    二、position對象

    當(dāng)成功獲取地理位置信息時候,onsuccess方法中會返回position對象,通過這個對象可以獲取地理位置的相關(guān)信息,包括:

    position對象的屬性:     latitude,//緯度    longitude,//經(jīng)度    altitude,//海拔高度    accuracy,//獲取緯度或者經(jīng)度的精度    altitudeAccurancy,//海拔高度的精度    heading,//設(shè)備前景方向。正北方向的順時針旋轉(zhuǎn)角    speed,//設(shè)備的前進(jìn)速度 m/s    timestamp,//獲取地理位置信息時候的時間

    三、基于google map的例子

    直接看代碼:

    <!DOCTYPE HTML>  <html>  <head>      <meta charset="UTF-8">      <title>在頁面上使用google地圖示例</title>  </head>  <body onload = 'init()'>      <div id="map" style='width:800px;height:800px;'></div>      <script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false'></script>      <script type="text/javascript">          function init(){              if(navigator.geolocation){                  navigator.geolocation.getCurrentPosition(function(pos){                          var coords = pos.coords;                          var latlng =new google.maps.LatLng(coords.latitude,coords.longitude);                          var options = {zoom:14,center:latlng,mapTypeId : google.maps.MapTypeId.ROADMAP};                          var map1;                          map1 =new google.maps.Map(document.getElementById('map'),options);                          var marker =new google.maps.Marker({                                  position : latlng,                                  map : map1                                  });                          var infowindow =new google.maps.InfoWindow({                                 content : '當(dāng)前位置!'                                 });                          infowindow.open(map1,marker);                          });              }          }      </script>        </body>  </html>

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號