<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 使用定位服務 **HTML5中為我們提供了定位API能夠讓我們實現獲取經緯度等位置信息。** **可以通過**`navigator.geolocation`**來獲取設備的當前位置,返回一個位置對象。** > **我們主要使用**`getCurrentPosition()`**這個方法。** > 使用方法`navigator.geolocation.getCurrentPosition(successCallback, [errorCallback] , [positionOptions]);` successCallback返回一個地理數據對象position作為參數,該對象有屬性timestamp和coords。timestamp表示該地理數據創建時間(時間戳);coords包括另外七個屬性: * coords.latitude:估計緯度 * coords.longitude:估計經度 * coords.altitude:估計高度 * coords.accuracy:所提供的以米為單位的經度和緯度估計的精確度 * coords.altitudeAccuracy:所提供的以米為單位的高度估計的精確度 * coords.heading: 宿主設備當前移動的角度方向,相對于正北方向順時針計算 * coords.speed:以米每秒為單位的設備的當前對地速度 ``` navigator.geolocation.getCurrentPosition(function(position){ var lat = position.coords.latitude; var lon = position.coords.longtitude; console.log(lat+" "+lon); }, function(error){ console.log(error); }); ``` >好像尷尬了!HTML5的定位是去請求googleapis.com,可是國內的網絡環境。。。 **所以,我們只能求助于百度地圖了!** 首先要去百度開發者,注冊應用 然后引入百度地圖的js文件 ```js <script src="http://api.map.baidu.com/api?v=2.0&ak=y4ks32wpzCHXIl6HIbuQeHSbGPEE2gkF" type="text/javascript"></script> ``` 使用百度地圖提供的方法。 注意,getLocation的回調函數需要一定時間等待才被調用。 ```js var geolocation = new BMap.Geolocation(); geolocation.getCurrentPosition(function (r) { if (this.getStatus() == BMAP_STATUS_SUCCESS) { currentLat = r.point.lat; currentLon = r.point.lng; var pt = new BMap.Point(currentLon, currentLat); var geoc = new BMap.Geocoder(); geoc.getLocation(pt, function (rs) { var addComp = rs.addressComponents; var city = addComp.city; console.log(city); //將城市后面的市去掉 console.log(city.slice(0,-1)); cityText = city.slice(0,-1); var city = encodeURIComponent(cityText); var key = 'f83bb390e68599c746b9124b7b21fbc8'; var url = "http://v.juhe.cn/weather/index?format=2&cityname="+city+"&key="+key; getData(url); }) }; }); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看