wx.openLocation调取失败

来源:互联网 发布:acrobat xi mac 破解 编辑:程序博客网 时间:2024/05/18 10:31

http://www.cnblogs.com/lilyYoung/p/7211874.html

在调取地图的时候发现,wx.openLocation的方法在模拟器和安卓手机上都可以用,在苹果手机上报错。

报错为调取失败:fail invoke too frequently                     fail invalid_coordinate

 

 

 

解决方法:

微信小程序默认将组件上绑定的参数都当作字符串了,所以认为坐标点不正确,强制转换成number类型即可。

  var lat = Number(e.currentTarget.dataset.lat),  
      lng = Number(e.currentTarget.dataset.lng), 
      name = e.currentTarget.dataset.name,
      address = e.currentTarget.dataset.address;

wx.openLocation({
      latitude: lat,
      longitude: lng,
      scale: 18,
      name: name,
      address: address,
      success: function (res) {
        console.log(res)
      },
      fail: function (res){
        console.log(res)
      }
    })