總結:運行不成功要注意是否是fail了胃惜,引用別人的接口要注意fail問題
從?https://lbs.qq.com/?中下載了?qqmap-wx-jssdk.js
其中要用于定位功能壮莹,并且要顯示所在位置的文字信息
查找網上資料杠氢,知道要用到?reverseGeocoder? 函數獲取位置信息
但是把reverseGeocoder寫進代碼榔幸,卻斷點斷不下來,
后來發(fā)現原來是返回fail了外驱,所以success中斷不下來,
fail的信息是??WebService? 沒有勾選衩婚,
然后
在其網頁勾選??WebServiceAPI后咒林,成功運行??
代碼如下:
```
getMyLocation: function(){
? ? var that = this
? ? wx.showLoading({
? ? ? title: "定位中",
? ? ? mask: true
? ? })
? ? wx.getLocation({
? ? ? type: 'gcj02',
? ? ? altitude: true,//高精度定位
? ? ? //定位成功,更新定位結果
? ? ? success: function (res) {
? ? ? ? var latitude = res.latitude
? ? ? ? var longitude = res.longitude
? ? ? ? var speed = res.speed
? ? ? ? var accuracy = res.accuracy
? ? ? ? that.setData({
? ? ? ? ? longitude: longitude,
? ? ? ? ? latitude: latitude,
? ? ? ? ? speed: speed,
? ? ? ? ? accuracy: accuracy
? ? ? ? })
? ? ? ? app.globalData.qqmapsdk.reverseGeocoder({
? ? ? ? ? location: {
? ? ? ? ? ? latitude: latitude,
? ? ? ? ? ? longitude: longitude
? ? ? ? ? },
? ? ? ? ? success: function (addressRes) {
? ? ? ? ? ? var address = addressRes.result.formatted_addresses.recommend;
? ? ? ? ? ? console.log(address);
? ? ? ? ? ? that.setData({
? ? ? ? ? ? ? str: address
? ? ? ? ? ? })
? ? ? ? ? }
? ? ? ? })
? ? ? },
? ? ? //定位失敗回調
? ? ? fail: function () {
? ? ? ? wx.showToast({
? ? ? ? ? title: "定位失敗",
? ? ? ? ? icon: "none"
? ? ? ? })
? ? ? },
? ? ? complete: function () {
? ? ? ? //隱藏定位中信息進度
? ? ? ? wx.hideLoading()
? ? ? }
? ? })
? }
```