qqmap-wx-jssdk中的reverseGeocoder不

2019-02-23  本文已影响0人  家辉sama

总结:运行不成功要注意是否是fail了,引用别人的接口要注意fail问题


从 https://lbs.qq.com/ 中下载了 qqmap-wx-jssdk.js

其中要用于定位功能,并且要显示所在位置的文字信息

查找网上资料,知道要用到 reverseGeocoder  函数获取位置信息

但是把reverseGeocoder写进代码,却断点断不下来,

后来发现原来是返回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()

      }

    })

  }

```

上一篇 下一篇

猜你喜欢

热点阅读