[备忘]微信小程序使用腾讯位置服务地图选点

微信截图_20220329153213.png

如上图,要勾选两处

  • 需要在小程序后台,添加上插件

设置 > 第三方设置 > 插件管理

微信截图_20220329154125.png
  • 需要将插件配置到小程序中
{
  "permission": {
    "scope.userLocation": {
      "desc": "你的位置信息将用于小程序定位"
    }
  },
  "plugins": {
    "chooseLocation": {
      "version": "1.0.9",
      "provider": "wx76a9a06e5b4e693e"
    }
  }
}

调用片段记录如下:


//这句提到最外层
const wxMiniPluginChooseLocation = requirePlugin('chooseLocation');

onUnload(){
  // 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
  wxMiniPluginChooseLocation.setLocation(null);
},
onShow(){
  if (this.flagNavToPluginMap) {
    this.flagNavToPluginMap = false;
    const location = wxMiniPluginChooseLocation.getLocation();
    console.log("location: ", location)
    if (location) {
      this.addInfo.province = location.province
      this.addInfo.city = location.city
      this.addInfo.area = location.district
      //addrDetail,longitude,latitude,
      this.addInfo.addrDetail = location.address
      this.addInfo.longitude = location.longitude
      this.addInfo.latitude = location.latitude
    }
  }
},
methods: {
  //通过小程序插件获取地址信息
  invokeWxMiniPluginGetLocation() {
    const key = wxMiniPluginMapLocationKey
    const referer = currentAppName
    const location = JSON.stringify({
      latitude: 39.89631551,
      longitude: 116.323459711
    });
    const category = '生活服务,娱乐休闲';
    this.flagNavToPluginMap = true;
    wx.navigateTo({
      // url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer 
      // + '&location=' + location + '&category=' + category
      url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer
    })
  },
}

End

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容