微信小程序仿饿了么地址定位、筛选与回传,微信共享实时位置修改

来源:未知 浏览 160次 时间 2021-06-10 14:01

通过本文你可以了解到:

微信小程序仿饿了么地址定位、筛选与回传

先来浏览一下效果图:

微信小程序仿饿了么地址定位、筛选与回传

1.自动定位以及返回10个相近位置

核心代码如下:

//引入类库 var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js') qqmapsdk = new QQMapWX({ key: 'BJFBZ-ZFTHW-Y2HRO-RL2UZ-M6EC3-GMF4U' }); qqmapsdk.reverseGeocoder({ get_poi: 1, success: function(res){ that.setData({ currentAddress: res.result.formatted_addresses.recommend, city: res.result.address_component.city, result: res.result.pois }); } });

其中get_poi设置为1可以返回得到当前定位周边的10个相近位置

2.关键字搜索

核心代码:

var keyword = e.detail.value; qqmapsdk.getSuggestion({ keyword: keyword, region: that.data.city, success: function(res){ that.setData({ result: res.data }); } });

其中region参数网站排名下降可以返回得到当前定位周边的10个相近位置

2.关键字搜索

核心代码:

var keyword = e.detail.value; qqmapsdk.getSuggestion({ keyword: keyword, region: that.data.city, success: function(res){ that.setData({ result: res.data }); } });

其中region参数传入之前reverseGeocoder获取得到的城市信息以过滤非本城市以外的其他搜索结果。

回传数据到首页

这里用到了第三方库WxNotification

下载地址:https://github.com/icindy/WxNotificationCenter

核心方法如下:

//引入类库 var WxNotificationCenter = require("../../utils/WxNotificationCenter.js"); //index.js 初始化注册通知 WxNotificationCenter.addNotification("getAddressNotification",that.getAddress,that) //index.js 监听通知网站排名以过滤非本城市以外的其他搜索结果。

回传数据到首页

这里用到了第三方库WxNotification

下载地址:https://github.com/icindy/WxNotificationCenter

核心方法如下:

//引入类库 var WxNotificationCenter = require("../../utils/WxNotificationCenter.js"); //index.js 初始化注册通知 WxNotificationCenter.addNotification("getAddressNotification",that.getAddress,that) //index.js 监听通知通过成员方法getAddress回调得到期望的参数值address WxNotificationCenter.addNotification("addressSelectedNotification",that.getAddress,that) //search.js 发送通知带上address参数值 WxNotificationCenter.postNotificationName("addressSelectedNotification", address);

实现getAddress方法

标签: 定位地址address通过