在公衆號裏的,實現個小功能,定位當前城市。 一開始用的百度的,在chrome裏測試一切正常。 放在手機端上訪問每次刷新 都提示受權 ~~~~ 。後面用微信內置的地理接口。就就正常了。html
微信地理位置接口: openLocation: 使用微信內置地圖查看位置接口 getLocation: 獲取地理位置接口。git
結合百度地圖:chrome
loadCity: function () { wx.getLocation({ type: 'wgs84', success: function (res) { // 建立地理編碼實例 var myGeo = new BMap.Geocoder(); // 根據座標獲得地址描述 myGeo.getLocation(new BMap.Point(res.longitude, res.latitude), function (result) { if (result) { $('#location').html('<i class="iconfont icon-location"></i>' + result.addressComponents.province + " " + result.addressComponents.city); } }) } }); }