久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      HTML5地理定位實(shí)例講解

      HTML5 Geolocation(地理定位)用于定位用戶的位置。

      定位用戶的位置

      HTML5 Geolocation API 用于獲得用戶的地理位置。

      鑒于該特性可能侵犯用戶的隱私,除非用戶同意,否則用戶位置信息是不可用的。

      瀏覽器支持

      Internet Explorer 9+, Firefox, Chrome, Safari 和 Opera 支持Geolocation(地理定位).

      注意: Geolocation(地理定位)對(duì)于擁有 GPS 的設(shè)備,比如 iPhone,地理定位更加精確。

      HTML5 – 使用地理定位

      請(qǐng)使用 getCurrentPosition() 方法來(lái)獲得用戶的位置。

      下例是一個(gè)簡(jiǎn)單的地理定位實(shí)例,可返回用戶位置的經(jīng)度和緯度:

      實(shí)例

      <script>  var x=document.getElementById("demo");  function getLocation()    {    if (navigator.geolocation)      {      navigator.geolocation.getCurrentPosition(showPosition);      }    else{x.innerHTML="該瀏覽器不支持獲取地理位置。";}    }  function showPosition(position)    {    x.innerHTML="Latitude: " + position.coords.latitude +     "<br>Longitude: " + position.coords.longitude;     }  </script>

      實(shí)例解析:

      檢測(cè)是否支持地理定位

      如果支持,則運(yùn)行 getCurrentPosition() 方法。如果不支持,則向用戶顯示一段消息。

      如果getCurrentPosition()運(yùn)行成功,則向參數(shù)showPosition中規(guī)定的函數(shù)返回一個(gè)coordinates對(duì)象

      showPosition() 函數(shù)獲得并顯示經(jīng)度和緯度

      上面的例子是一個(gè)非?;A(chǔ)的地理定位腳本,不含錯(cuò)誤處理。

      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;      }    }

      錯(cuò)誤代碼:

      Permission denied – 用戶不允許地理定位

      Position unavailable – 無(wú)法獲取當(dāng)前位置

      Timeout – 操作超時(shí)

      在地圖中顯示結(jié)果

      如需在地圖中顯示結(jié)果,您需要訪問(wèn)可使用經(jīng)緯度的地圖服務(wù),比如谷歌地圖或百度地圖:

      function showPosition(position)  {  var latlon=position.coords.latitude+","+position.coords.longitude;  var img_url="http://maps.googleapis.com/maps/api/staticmap?center="  +latlon+"&zoom=14&size=400x300&sensor=false";  document.getElementById("mapholder").innerHTML="<img src='"+img_url+"'>";  }

      在上例中,我們使用返回的經(jīng)緯度數(shù)據(jù)在谷歌地圖中顯示位置(使用靜態(tài)圖像)。

      Google地圖腳本
      上面的鏈接向您演示如何使用腳本來(lái)顯示帶有標(biāo)記、縮放和拖曳選項(xiàng)的交互式地圖。

      給定位置的信息

      本頁(yè)演示的是如何在地圖上顯示用戶的位置。不過(guò),地理定位對(duì)于給定位置的信息同樣很有用處。

      實(shí)例:

      更新本地信息

      顯示用戶周圍的興趣點(diǎn)

      交互式車載導(dǎo)航系統(tǒng) (GPS)

      getCurrentPosition() 方法 – 返回?cái)?shù)據(jù)

      T若成功,則 getCurrentPosition() 方法返回對(duì)象。始終會(huì)返回 latitude、longitude 以及 accuracy 屬性。

      Geolocation 對(duì)象 – 其他有趣的方法

      watchPosition() – 返回用戶的當(dāng)前位置,并繼續(xù)返回用戶移動(dòng)時(shí)的更新位置(就像汽車上的 GPS)。

      clearWatch() – 停止 watchPosition() 方法

      下面的例子展示 watchPosition() 方法。您需要一臺(tái)精確的 GPS 設(shè)備來(lái)測(cè)試該例(比如 iPhone):

      <script>  var x=document.getElementById("demo");  function getLocation()    {    if (navigator.geolocation)      {      navigator.geolocation.watchPosition(showPosition);      }    else{x.innerHTML="該瀏覽器不支持獲取地理位置。";}    }  function showPosition(position)    {    x.innerHTML="緯度: " + position.coords.latitude +     "<br>經(jīng)度: " + position.coords.longitude;     }  </script>

      【相關(guān)推薦】

      1. 特別推薦:“php程序員工具箱”V0.1版本下載

      2. 免費(fèi)h5在線視頻教程

      3. php.cn原創(chuàng)html5視頻教程

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