使用微信小程序制作核酸检测点查询工具

目录
  • 全国省市区数据
  • 拼接参数调用接口
  • 渲染数据优化细节

出门在外,没有核酸证明寸步难行,此文将教你如何通过小程序制作一个工具帮你在人生地不熟的情况如何迅速找到核酸检测点,实现核酸点查询、地图导航、拨号等功能。

小程序 创建小程序

访问微信公众平台,点击账号注册。

  1. 选择小程序,并在表单填写所需的各项信息进行注册。


  1. 在开发管理选择开发设置,将AppID及AppSecret复制出来进行存储。

  1. 下载安装微信web开发者工具并创建一个新的项目,填入上图所复制的AppId。


申请腾讯地图用户key

访问腾讯位置服务,申请腾讯地图用户Key,因为在后面我们需要将用户的经纬度解析成地址,所以这个步骤是必不可少的

  1. 点击右上角的登陆,选择注册或绑定现有账号;绑定完毕后选择创建ApiKey


  1. 填写所需的各项表单信息,点击确定将所创建的API Key保存下来。

实现小程序界面

在页面上大致要实现选择省市区功能,然后通过点击查询按钮将核酸点数据进行渲染,实现导航及拨号等细节功能,设计如下。

  1. 在pages文件夹下面创建一个文件夹并新建对应的page文件。

  1. 在index.js中引入utils文件夹下面的引入腾讯地图SDK核心类。

const util = require("../../utils/util.js");
const app = getApp();
// 引入腾讯地图SDK核心类
var QQMapWX = require('../../utils/map/qqmap-wx-jssdk.js');
var qqmapsdk;
  1. 在JS中的onLoad函数中将其进行实例化,复制刚才在腾讯地图所申请的用户key。
 qqmapsdk = new QQMapWX({
      key: '刚刚所申请的key填到这里'
    });
  1. 实现省市区下拉框三级联动,这里需要用到的是picker组件,mode熟悉填写region。
<picker class="picker" mode="region" bindchange="bindPickerChange" value="{{region}}" custom-item="{{customItem}}">
    <view class="address little">
      <text>请选择: </text>
      <text> {{provinceName}} {{cityName}} {{districtName}}</text>
    </view>
  </picker>

  1. 同时实现该组件的响应函数,看是否能够获取到我们所需要的信息,正确响应如下图,然后根据数组下标取到对应的省市区并将其存储到全局的data中。

 bindPickerChange: function (e) {
    let that = this;
    let province = e.detail.value[0];
    let city = e.detail.value[1];
    let district = e.detail.value[2];
   	that .setData({
	     province : province,
	     city : city,
	     district: e.detail.value
   	});
  },
  1. picker组件在加载时候默认是不会选中的,为了优化用户体验,我们需要在加载的时候获取用户的位置并对其进行赋值,首先需要在app.json文件中增加配置。

"permission": {
    "scope.userLocation": {
      "desc": "位置信息效果展示"
    }
  },
	"requiredPrivateInfos": [
		"getLocation"
	]
  1. 回到index.js,在onLoad函数中调用wx.getLocation,这个函数是用于获取用户当前经纬度。

  1. 很显然,经纬度是不能够直接赋值给picker组件的,接下来需要逆解析将其转换为地址,这时候需要用到reverseGeocoder函数了,将上一个函数返回的经纬度作为参数拼接调用,返回的信息中就有我们需要的省市区等详细地址了。

//获取用户当前经纬度
    wx.getLocation({
      type: 'wgs84',
      success (data) {
        // 将用户经纬度转换为地址
        qqmapsdk.reverseGeocoder({//地址解析
          location: {
            longitude: data.longitude,
            latitude: data.latitude,
          },
          success: function (resSuc) {
            let province = resSuc.result.address_component.province;
            let city = resSuc.result.address_component.city;
            let district = resSuc.result.address_component.district;
            that.setData({
              province: province.substr(0, province.length - 1),
              city: city.substr(0, city.length - 1),
              provinceName:province,
              cityName:city,
              districtName:district
            });
          },
          fail: function (errInfo) {
          }
        });
      },
      fail: function (errInfo) {
        console.info(errInfo)
      }
     });

全国省市区数据

后续的接口请求中需要传递不同的城市code,所以现在现在需要封装一个JS,用于传参使用。在utils文件夹中新建一个js文件,将省份及城市数据存放其中,并进行初始化。

var cityData = [{
  "province_id": "1",
  "province": "安徽",
  "citys": [{
    "city_id": "10001",
    "city": "合肥"
  }, {
    "city_id": "10002",
    "city": "芜湖"
  }, {
    "city_id": "10003",
    "city": "蚌埠"
  }, {
    "city_id": "10004",
    "city": "淮南"
  }, {
    "city_id": "10005",
    "city": "马鞍山"
  }, {
    "city_id": "10006",
    "city": "淮北"
  }, {
    "city_id": "10007",
    "city": "铜陵"
  }, {
    "city_id": "10008",
    "city": "安庆"
  }, {
    "city_id": "10009",
    "city": "黄山"
  }, {
    "city_id": "10010",
    "city": "滁州"
  }, {
    "city_id": "10011",
    "city": "阜阳"
  }, {
    "city_id": "10012",
    "city": "宿州"
  }, {
    "city_id": "10013",
    "city": "六安"
  }, {
    "city_id": "10014",
    "city": "亳州"
  }, {
    "city_id": "10015",
    "city": "池州"
  }, {
    "city_id": "10016",
    "city": "宣城"
  }]
}, {
  "province_id": "2",
  "province": "北京",
  "citys": [{
    "city_id": "10017",
    "city": "北京"
  }]
}, {
  "province_id": "3",
  "province": "重庆",
  "citys": [{
    "city_id": "10018",
    "city": "重庆"
  }]
}, {
  "province_id": "4",
  "province": "福建",
  "citys": [{
    "city_id": "10019",
    "city": "福州"
  }, {
    "city_id": "10020",
    "city": "厦门"
  }, {
    "city_id": "10021",
    "city": "莆田"
  }, {
    "city_id": "10022",
    "city": "三明"
  }, {
    "city_id": "10023",
    "city": "泉州"
  }, {
    "city_id": "10024",
    "city": "漳州"
  }, {
    "city_id": "10025",
    "city": "南平"
  }, {
    "city_id": "10026",
    "city": "龙岩"
  }, {
    "city_id": "10027",
    "city": "宁德"
  }]
}, {
  "province_id": "5",
  "province": "广东",
  "citys": [{
    "city_id": "10028",
    "city": "广州"
  }, {
    "city_id": "10029",
    "city": "韶关"
  }, {
    "city_id": "10030",
    "city": "深圳"
  }, {
    "city_id": "10031",
    "city": "珠海"
  }, {
    "city_id": "10032",
    "city": "汕头"
  }, {
    "city_id": "10033",
    "city": "佛山"
  }, {
    "city_id": "10034",
    "city": "江门"
  }, {
    "city_id": "10035",
    "city": "湛江"
  }, {
    "city_id": "10036",
    "city": "茂名"
  }, {
    "city_id": "10037",
    "city": "肇庆"
  }, {
    "city_id": "10038",
    "city": "惠州"
  }, {
    "city_id": "10039",
    "city": "梅州"
  }, {
    "city_id": "10040",
    "city": "汕尾"
  }, {
    "city_id": "10041",
    "city": "河源"
  }, {
    "city_id": "10042",
    "city": "阳江"
  }, {
    "city_id": "10043",
    "city": "清远"
  }, {
    "city_id": "10044",
    "city": "东莞"
  }, {
    "city_id": "10045",
    "city": "中山"
  }, {
    "city_id": "10046",
    "city": "潮州"
  }, {
    "city_id": "10047",
    "city": "揭阳"
  }, {
    "city_id": "10048",
    "city": "云浮"
  }]
}, {
  "province_id": "6",
  "province": "甘肃",
  "citys": [{
    "city_id": "10049",
    "city": "兰州"
  }, {
    "city_id": "10050",
    "city": "嘉峪关"
  }, {
    "city_id": "10051",
    "city": "金昌"
  }, {
    "city_id": "10052",
    "city": "白银"
  }, {
    "city_id": "10053",
    "city": "天水"
  }, {
    "city_id": "10054",
    "city": "武威"
  }, {
    "city_id": "10055",
    "city": "张掖"
  }, {
    "city_id": "10056",
    "city": "平凉"
  }, {
    "city_id": "10057",
    "city": "酒泉"
  }, {
    "city_id": "10058",
    "city": "庆阳"
  }, {
    "city_id": "10059",
    "city": "定西"
  }, {
    "city_id": "10060",
    "city": "陇南"
  }, {
    "city_id": "10061",
    "city": "临夏"
  }, {
    "city_id": "10062",
    "city": "甘南"
  }]
}, {
  "province_id": "7",
  "province": "广西",
  "citys": [{
    "city_id": "10063",
    "city": "南宁"
  }, {
    "city_id": "10064",
    "city": "柳州"
  }, {
    "city_id": "10065",
    "city": "桂林"
  }, {
    "city_id": "10066",
    "city": "梧州"
  }, {
    "city_id": "10067",
    "city": "北海"
  }, {
    "city_id": "10068",
    "city": "防城港"
  }, {
    "city_id": "10069",
    "city": "钦州"
  }, {
    "city_id": "10070",
    "city": "贵港"
  }, {
    "city_id": "10071",
    "city": "玉林"
  }, {
    "city_id": "10072",
    "city": "百色"
  }, {
    "city_id": "10073",
    "city": "贺州"
  }, {
    "city_id": "10074",
    "city": "河池"
  }, {
    "city_id": "10075",
    "city": "来宾"
  }, {
    "city_id": "10076",
    "city": "崇左"
  }]
}, {
  "province_id": "8",
  "province": "贵州",
  "citys": [{
    "city_id": "10077",
    "city": "贵阳"
  }, {
    "city_id": "10078",
    "city": "六盘水"
  }, {
    "city_id": "10079",
    "city": "遵义"
  }, {
    "city_id": "10080",
    "city": "安顺"
  }, {
    "city_id": "10081",
    "city": "毕节"
  }, {
    "city_id": "10082",
    "city": "铜仁"
  }, {
    "city_id": "10083",
    "city": "黔西南"
  }, {
    "city_id": "10084",
    "city": "黔东南"
  }, {
    "city_id": "10085",
    "city": "黔南"
  }]
}, {
  "province_id": "9",
  "province": "河北",
  "citys": [{
    "city_id": "10086",
    "city": "石家庄"
  }, {
    "city_id": "10087",
    "city": "唐山"
  }, {
    "city_id": "10088",
    "city": "秦皇岛"
  }, {
    "city_id": "10089",
    "city": "邯郸"
  }, {
    "city_id": "10090",
    "city": "邢台"
  }, {
    "city_id": "10091",
    "city": "保定"
  }, {
    "city_id": "10092",
    "city": "张家口"
  }, {
    "city_id": "10093",
    "city": "承德"
  }, {
    "city_id": "10094",
    "city": "沧州"
  }, {
    "city_id": "10095",
    "city": "廊坊"
  }, {
    "city_id": "10096",
    "city": "衡水"
  }]
}, {
  "province_id": "10",
  "province": "湖北",
  "citys": [{
    "city_id": "10097",
    "city": "武汉"
  }, {
    "city_id": "10098",
    "city": "黄石"
  }, {
    "city_id": "10099",
    "city": "十堰"
  }, {
    "city_id": "10100",
    "city": "宜昌"
  }, {
    "city_id": "10101",
    "city": "襄阳"
  }, {
    "city_id": "10102",
    "city": "鄂州"
  }, {
    "city_id": "10103",
    "city": "荆门"
  }, {
    "city_id": "10104",
    "city": "孝感"
  }, {
    "city_id": "10105",
    "city": "荆州"
  }, {
    "city_id": "10106",
    "city": "黄冈"
  }, {
    "city_id": "10107",
    "city": "咸宁"
  }, {
    "city_id": "10108",
    "city": "随州"
  }, {
    "city_id": "10109",
    "city": "恩施"
  }, {
    "city_id": "10110",
    "city": "仙桃"
  }, {
    "city_id": "10111",
    "city": "潜江"
  }, {
    "city_id": "10112",
    "city": "天门"
  }, {
    "city_id": "10113",
    "city": "神农架"
  }]
}, {
  "province_id": "11",
  "province": "黑龙江",
  "citys": [{
    "city_id": "10114",
    "city": "哈尔滨"
  }, {
    "city_id": "10115",
    "city": "齐齐哈尔"
  }, {
    "city_id": "10116",
    "city": "鸡西"
  }, {
    "city_id": "10117",
    "city": "鹤岗"
  }, {
    "city_id": "10118",
    "city": "双鸭山"
  }, {
    "city_id": "10119",
    "city": "大庆"
  }, {
    "city_id": "10120",
    "city": "伊春"
  }, {
    "city_id": "10121",
    "city": "佳木斯"
  }, {
    "city_id": "10122",
    "city": "七台河"
  }, {
    "city_id": "10123",
    "city": "牡丹江"
  }, {
    "city_id": "10124",
    "city": "黑河"
  }, {
    "city_id": "10125",
    "city": "绥化"
  }, {
    "city_id": "10126",
    "city": "大兴安岭"
  }]
}, {
  "province_id": "12",
  "province": "海南",
  "citys": [{
    "city_id": "10127",
    "city": "海口"
  }, {
    "city_id": "10128",
    "city": "三亚"
  }, {
    "city_id": "10129",
    "city": "三沙"
  }, {
    "city_id": "10130",
    "city": "儋州"
  }, {
    "city_id": "10131",
    "city": "五指山"
  }, {
    "city_id": "10132",
    "city": "琼海"
  }, {
    "city_id": "10133",
    "city": "文昌"
  }, {
    "city_id": "10134",
    "city": "万宁"
  }, {
    "city_id": "10135",
    "city": "东方"
  }, {
    "city_id": "10136",
    "city": "定安"
  }, {
    "city_id": "10137",
    "city": "屯昌"
  }, {
    "city_id": "10138",
    "city": "澄迈"
  }, {
    "city_id": "10139",
    "city": "临高"
  }, {
    "city_id": "10140",
    "city": "白沙"
  }, {
    "city_id": "10141",
    "city": "昌江"
  }, {
    "city_id": "10142",
    "city": "乐东"
  }, {
    "city_id": "10143",
    "city": "陵水"
  }, {
    "city_id": "10144",
    "city": "保亭"
  }, {
    "city_id": "10145",
    "city": "琼中"
  }]
}, {
  "province_id": "13",
  "province": "河南",
  "citys": [{
    "city_id": "10146",
    "city": "郑州"
  }, {
    "city_id": "10147",
    "city": "开封"
  }, {
    "city_id": "10148",
    "city": "洛阳"
  }, {
    "city_id": "10149",
    "city": "平顶山"
  }, {
    "city_id": "10150",
    "city": "安阳"
  }, {
    "city_id": "10151",
    "city": "鹤壁"
  }, {
    "city_id": "10152",
    "city": "新乡"
  }, {
    "city_id": "10153",
    "city": "焦作"
  }, {
    "city_id": "10154",
    "city": "濮阳"
  }, {
    "city_id": "10155",
    "city": "许昌"
  }, {
    "city_id": "10156",
    "city": "漯河"
  }, {
    "city_id": "10157",
    "city": "三门峡"
  }, {
    "city_id": "10158",
    "city": "南阳"
  }, {
    "city_id": "10159",
    "city": "商丘"
  }, {
    "city_id": "10160",
    "city": "信阳"
  }, {
    "city_id": "10161",
    "city": "周口"
  }, {
    "city_id": "10162",
    "city": "驻马店"
  }, {
    "city_id": "10163",
    "city": "济源"
  }]
}, {
  "province_id": "14",
  "province": "湖南",
  "citys": [{
    "city_id": "10164",
    "city": "长沙"
  }, {
    "city_id": "10165",
    "city": "株洲"
  }, {
    "city_id": "10166",
    "city": "湘潭"
  }, {
    "city_id": "10167",
    "city": "衡阳"
  }, {
    "city_id": "10168",
    "city": "邵阳"
  }, {
    "city_id": "10169",
    "city": "岳阳"
  }, {
    "city_id": "10170",
    "city": "常德"
  }, {
    "city_id": "10171",
    "city": "张家界"
  }, {
    "city_id": "10172",
    "city": "益阳"
  }, {
    "city_id": "10173",
    "city": "郴州"
  }, {
    "city_id": "10174",
    "city": "永州"
  }, {
    "city_id": "10175",
    "city": "怀化"
  }, {
    "city_id": "10176",
    "city": "娄底"
  }, {
    "city_id": "10177",
    "city": "湘西"
  }]
}, {
  "province_id": "15",
  "province": "吉林",
  "citys": [{
    "city_id": "10178",
    "city": "长春"
  }, {
    "city_id": "10179",
    "city": "吉林"
  }, {
    "city_id": "10180",
    "city": "四平"
  }, {
    "city_id": "10181",
    "city": "辽源"
  }, {
    "city_id": "10182",
    "city": "通化"
  }, {
    "city_id": "10183",
    "city": "白山"
  }, {
    "city_id": "10184",
    "city": "松原"
  }, {
    "city_id": "10185",
    "city": "白城"
  }, {
    "city_id": "10186",
    "city": "延边"
  }]
}, {
  "province_id": "16",
  "province": "江苏",
  "citys": [{
    "city_id": "10187",
    "city": "南京"
  }, {
    "city_id": "10188",
    "city": "无锡"
  }, {
    "city_id": "10189",
    "city": "徐州"
  }, {
    "city_id": "10190",
    "city": "常州"
  }, {
    "city_id": "10191",
    "city": "苏州"
  }, {
    "city_id": "10192",
    "city": "南通"
  }, {
    "city_id": "10193",
    "city": "连云港"
  }, {
    "city_id": "10194",
    "city": "淮安"
  }, {
    "city_id": "10195",
    "city": "盐城"
  }, {
    "city_id": "10196",
    "city": "扬州"
  }, {
    "city_id": "10197",
    "city": "镇江"
  }, {
    "city_id": "10198",
    "city": "泰州"
  }, {
    "city_id": "10199",
    "city": "宿迁"
  }]
}, {
  "province_id": "17",
  "province": "江西",
  "citys": [{
    "city_id": "10200",
    "city": "南昌"
  }, {
    "city_id": "10201",
    "city": "景德镇"
  }, {
    "city_id": "10202",
    "city": "萍乡"
  }, {
    "city_id": "10203",
    "city": "九江"
  }, {
    "city_id": "10204",
    "city": "新余"
  }, {
    "city_id": "10205",
    "city": "鹰潭"
  }, {
    "city_id": "10206",
    "city": "赣州"
  }, {
    "city_id": "10207",
    "city": "吉安"
  }, {
    "city_id": "10208",
    "city": "宜春"
  }, {
    "city_id": "10209",
    "city": "抚州"
  }, {
    "city_id": "10210",
    "city": "上饶"
  }]
}, {
  "province_id": "18",
  "province": "辽宁",
  "citys": [{
    "city_id": "10211",
    "city": "沈阳"
  }, {
    "city_id": "10212",
    "city": "大连"
  }, {
    "city_id": "10213",
    "city": "鞍山"
  }, {
    "city_id": "10214",
    "city": "抚顺"
  }, {
    "city_id": "10215",
    "city": "本溪"
  }, {
    "city_id": "10216",
    "city": "丹东"
  }, {
    "city_id": "10217",
    "city": "锦州"
  }, {
    "city_id": "10218",
    "city": "营口"
  }, {
    "city_id": "10219",
    "city": "阜新"
  }, {
    "city_id": "10220",
    "city": "辽阳"
  }, {
    "city_id": "10221",
    "city": "盘锦"
  }, {
    "city_id": "10222",
    "city": "铁岭"
  }, {
    "city_id": "10223",
    "city": "朝阳"
  }, {
    "city_id": "10224",
    "city": "葫芦岛"
  }]
}, {
  "province_id": "19",
  "province": "内蒙古",
  "citys": [{
    "city_id": "10225",
    "city": "呼和浩特"
  }, {
    "city_id": "10226",
    "city": "包头"
  }, {
    "city_id": "10227",
    "city": "乌海"
  }, {
    "city_id": "10228",
    "city": "赤峰"
  }, {
    "city_id": "10229",
    "city": "通辽"
  }, {
    "city_id": "10230",
    "city": "鄂尔多斯"
  }, {
    "city_id": "10231",
    "city": "呼伦贝尔"
  }, {
    "city_id": "10232",
    "city": "巴彦淖尔"
  }, {
    "city_id": "10233",
    "city": "乌兰察布"
  }, {
    "city_id": "10234",
    "city": "兴安"
  }, {
    "city_id": "10235",
    "city": "锡林郭勒"
  }, {
    "city_id": "10236",
    "city": "阿拉善"
  }]
}, {
  "province_id": "20",
  "province": "宁夏",
  "citys": [{
    "city_id": "10237",
    "city": "银川"
  }, {
    "city_id": "10238",
    "city": "石嘴山"
  }, {
    "city_id": "10239",
    "city": "吴忠"
  }, {
    "city_id": "10240",
    "city": "固原"
  }, {
    "city_id": "10241",
    "city": "中卫"
  }]
}, {
  "province_id": "21",
  "province": "青海",
  "citys": [{
    "city_id": "10242",
    "city": "西宁"
  }, {
    "city_id": "10243",
    "city": "海东"
  }, {
    "city_id": "10244",
    "city": "海北"
  }, {
    "city_id": "10245",
    "city": "黄南"
  }, {
    "city_id": "10246",
    "city": "海南"
  }, {
    "city_id": "10247",
    "city": "果洛"
  }, {
    "city_id": "10248",
    "city": "玉树"
  }, {
    "city_id": "10249",
    "city": "海西"
  }]
}, {
  "province_id": "22",
  "province": "四川",
  "citys": [{
    "city_id": "10250",
    "city": "成都"
  }, {
    "city_id": "10251",
    "city": "自贡"
  }, {
    "city_id": "10252",
    "city": "攀枝花"
  }, {
    "city_id": "10253",
    "city": "泸州"
  }, {
    "city_id": "10254",
    "city": "德阳"
  }, {
    "city_id": "10255",
    "city": "绵阳"
  }, {
    "city_id": "10256",
    "city": "广元"
  }, {
    "city_id": "10257",
    "city": "遂宁"
  }, {
    "city_id": "10258",
    "city": "内江"
  }, {
    "city_id": "10259",
    "city": "乐山"
  }, {
    "city_id": "10260",
    "city": "南充"
  }, {
    "city_id": "10261",
    "city": "眉山"
  }, {
    "city_id": "10262",
    "city": "宜宾"
  }, {
    "city_id": "10263",
    "city": "广安"
  }, {
    "city_id": "10264",
    "city": "达州"
  }, {
    "city_id": "10265",
    "city": "雅安"
  }, {
    "city_id": "10266",
    "city": "巴中"
  }, {
    "city_id": "10267",
    "city": "资阳"
  }, {
    "city_id": "10268",
    "city": "阿坝"
  }, {
    "city_id": "10269",
    "city": "甘孜"
  }, {
    "city_id": "10270",
    "city": "凉山"
  }]
}, {
  "province_id": "23",
  "province": "山东",
  "citys": [{
    "city_id": "10271",
    "city": "济南"
  }, {
    "city_id": "10272",
    "city": "青岛"
  }, {
    "city_id": "10273",
    "city": "淄博"
  }, {
    "city_id": "10274",
    "city": "枣庄"
  }, {
    "city_id": "10275",
    "city": "东营"
  }, {
    "city_id": "10276",
    "city": "烟台"
  }, {
    "city_id": "10277",
    "city": "潍坊"
  }, {
    "city_id": "10278",
    "city": "济宁"
  }, {
    "city_id": "10279",
    "city": "泰安"
  }, {
    "city_id": "10280",
    "city": "威海"
  }, {
    "city_id": "10281",
    "city": "日照"
  }, {
    "city_id": "10282",
    "city": "临沂"
  }, {
    "city_id": "10283",
    "city": "德州"
  }, {
    "city_id": "10284",
    "city": "聊城"
  }, {
    "city_id": "10285",
    "city": "滨州"
  }, {
    "city_id": "10286",
    "city": "菏泽"
  }]
}, {
  "province_id": "24",
  "province": "上海",
  "citys": [{
    "city_id": "10287",
    "city": "上海"
  }]
}, {
  "province_id": "25",
  "province": "山西",
  "citys": [{
    "city_id": "10288",
    "city": "太原"
  }, {
    "city_id": "10289",
    "city": "大同"
  }, {
    "city_id": "10290",
    "city": "阳泉"
  }, {
    "city_id": "10291",
    "city": "长治"
  }, {
    "city_id": "10292",
    "city": "晋城"
  }, {
    "city_id": "10293",
    "city": "朔州"
  }, {
    "city_id": "10294",
    "city": "晋中"
  }, {
    "city_id": "10295",
    "city": "运城"
  }, {
    "city_id": "10296",
    "city": "忻州"
  }, {
    "city_id": "10297",
    "city": "临汾"
  }, {
    "city_id": "10298",
    "city": "吕梁"
  }]
}, {
  "province_id": "26",
  "province": "陕西",
  "citys": [{
    "city_id": "10299",
    "city": "西安"
  }, {
    "city_id": "10300",
    "city": "铜川"
  }, {
    "city_id": "10301",
    "city": "宝鸡"
  }, {
    "city_id": "10302",
    "city": "咸阳"
  }, {
    "city_id": "10303",
    "city": "渭南"
  }, {
    "city_id": "10304",
    "city": "延安"
  }, {
    "city_id": "10305",
    "city": "汉中"
  }, {
    "city_id": "10306",
    "city": "榆林"
  }, {
    "city_id": "10307",
    "city": "安康"
  }, {
    "city_id": "10308",
    "city": "商洛"
  }]
}, {
  "province_id": "27",
  "province": "天津",
  "citys": [{
    "city_id": "10309",
    "city": "天津"
  }]
}, {
  "province_id": "28",
  "province": "新疆",
  "citys": [{
    "city_id": "10310",
    "city": "乌鲁木齐"
  }, {
    "city_id": "10311",
    "city": "克拉玛依"
  }, {
    "city_id": "10312",
    "city": "吐鲁番"
  }, {
    "city_id": "10313",
    "city": "哈密"
  }, {
    "city_id": "10314",
    "city": "昌吉"
  }, {
    "city_id": "10315",
    "city": "博尔塔拉"
  }, {
    "city_id": "10316",
    "city": "巴音郭楞"
  }, {
    "city_id": "10317",
    "city": "阿克苏"
  }, {
    "city_id": "10318",
    "city": "克孜勒苏"
  }, {
    "city_id": "10319",
    "city": "喀什"
  }, {
    "city_id": "10320",
    "city": "和田"
  }, {
    "city_id": "10321",
    "city": "伊犁"
  }, {
    "city_id": "10322",
    "city": "塔城"
  }, {
    "city_id": "10323",
    "city": "阿勒泰"
  }]
}, {
  "province_id": "29",
  "province": "西藏",
  "citys": [{
    "city_id": "10324",
    "city": "拉萨"
  }, {
    "city_id": "10325",
    "city": "日喀则"
  }, {
    "city_id": "10326",
    "city": "昌都"
  }, {
    "city_id": "10327",
    "city": "林芝"
  }, {
    "city_id": "10328",
    "city": "山南"
  }, {
    "city_id": "10329",
    "city": "那曲"
  }, {
    "city_id": "10330",
    "city": "阿里"
  }]
}, {
  "province_id": "30",
  "province": "云南",
  "citys": [{
    "city_id": "10331",
    "city": "昆明"
  }, {
    "city_id": "10332",
    "city": "曲靖"
  }, {
    "city_id": "10333",
    "city": "玉溪"
  }, {
    "city_id": "10334",
    "city": "保山"
  }, {
    "city_id": "10335",
    "city": "昭通"
  }, {
    "city_id": "10336",
    "city": "丽江"
  }, {
    "city_id": "10337",
    "city": "普洱"
  }, {
    "city_id": "10338",
    "city": "临沧"
  }, {
    "city_id": "10339",
    "city": "楚雄"
  }, {
    "city_id": "10340",
    "city": "红河"
  }, {
    "city_id": "10341",
    "city": "文山"
  }, {
    "city_id": "10342",
    "city": "西双版纳"
  }, {
    "city_id": "10343",
    "city": "大理"
  }, {
    "city_id": "10344",
    "city": "德宏"
  }, {
    "city_id": "10345",
    "city": "怒江"
  }, {
    "city_id": "10346",
    "city": "迪庆"
  }]
}, {
  "province_id": "31",
  "province": "浙江",
  "citys": [{
    "city_id": "10347",
    "city": "杭州"
  }, {
    "city_id": "10348",
    "city": "宁波"
  }, {
    "city_id": "10349",
    "city": "温州"
  }, {
    "city_id": "10350",
    "city": "嘉兴"
  }, {
    "city_id": "10351",
    "city": "湖州"
  }, {
    "city_id": "10352",
    "city": "绍兴"
  }, {
    "city_id": "10353",
    "city": "金华"
  }, {
    "city_id": "10354",
    "city": "衢州"
  }, {
    "city_id": "10355",
    "city": "舟山"
  }, {
    "city_id": "10356",
    "city": "台州"
  }, {
    "city_id": "10357",
    "city": "丽水"
  }]
}, {
  "province_id": "32",
  "province": "台湾",
  "citys": [{
    "city_id": "10358",
    "city": "台湾"
  }]
}, {
  "province_id": "33",
  "province": "香港",
  "citys": [{
    "city_id": "10359",
    "city": "香港"
  }]
}, {
  "province_id": "34",
  "province": "澳门",
  "citys": [{
    "city_id": "10360",
    "city": "澳门"
  }]
}];

function init(that){
  that.setData( {
        'cityData': cityData
    });
}

module.exports={
    init:init
}

API 提交资料认证并申请接口

访问聚合数据,创建/登录账号,点击个人中心,填写对应的资料进行实名认证并申请对应的接口权限。
接口申请地址点此访问

拼接参数调用接口

可以看到调用该接口的参数很简单,只有用户应用key以及city_id,也就是我们上面所封装的省市区js里面的数据。

  1. 复制对应的key并实现从省市区JS中获取用户所选择的城市id。

  1. 因为picker组件所响应的值是某某省、某某市这样的数据,而我们所封装的JS数据中又是没有省跟市这些后缀的,所以在选择的时候需要将省市区进行最后一位的移除,然后再通过findIndex的方式找到对应的下标,通过下标再找到对应的city_id。

  1. 能够正常的获取到城市id后,我们就可以拼接参数调用接口了。

    wx.request({
      url: 'http://apis.juhe.cn/springTravel/hsjg?key=这里填写你的应用key&city_id=' + cityCode,
      method: 'get',
      contentType: "application/x-www-form-urlencoded",
      success: function (res) {
        that.setData({
          hospitalData: res.data.result.data
        });
      }
    });

渲染数据优化细节

查看接口返回并渲染数据,通过上面的步骤我们可以得到如下图,核酸检测点数据已经成功返回了。

  1. 在页面上定义对应的view及wx:for,将核酸检查点名称及电话进行展示。

  1. 在能将数据进行渲染之后,可以优化一些细节,例如导航及拨号等功能。

<image src="../../images/phone.png" class="phoneImg"></image>
 <image src="../../images/map.png" class="mapIcon" data-name="{{item.name}}" data-id="{{item.address}}" bindtap="goMap"></image>
  1. 拨号功能,在拨号图标实现对应的函数,将循环中的电话号码以data-id的方式进行传递。

    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.id,
      success: function () {
        console.log('成功拨打电话')
      }
    })
  1. 导航功能,在地图小图标上面将循环中的address字段以data-id的方式进行传递。因为唤醒地图需要准确的经纬度,所以我们这里还需要将检测点的地址进行转换,最后再使用wx.openLocation通过微信内置地图查看位置及导航。

  goMap(e) {
    let detail = e.currentTarget.dataset.id;
    let name = e.currentTarget.dataset.name;
    //地址转换经纬度
    qqmapsdk.geocoder({
      address: e.currentTarget.dataset.id,
      success: function (res) { //成功后的回调
        wx.openLocation({ //​使用微信内置地图查看位置。
          latitude: parseFloat(res.result.location.lat), //要去的纬度-地址
          longitude: parseFloat(res.result.location.lng), //要去的经度-地址
          name: name,
          address: detail
        })
      }
    });
  },

在路上碰到几个刚来的深漂拎着大包小包问哪里有核酸可以做,给他们指完方向后觉得可以开发一个小工具帮助出门在外的朋友,抗疫不仅仅是精神的对垒也是物质的角力。

到此这篇关于使用微信小程序制作一个核酸检测点查询工具的文章就介绍到这了,更多相关小程序核酸检测点查询工具内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • 微信小程序云开发实现数据添加、查询和分页

    本文实例为大家分享了微信小程序云开发实现数据添加.查询和分页,供大家参考,具体内容如下 实现的效果 实现要点 WXML 不同类别数据的显示 通过 if-elif-else 实现,在wxml文件中通过 <block></block>渲染,因为它仅仅是一个包装元素,不会在页面中做任何渲染,只接受控制属性.也就是说可以通过属性来控制页面是否要渲染这部分的内容,可以减少页面渲染时间. 云开发数据的获取 先开通云开发功能 ,参考官方文档,然后在创建项目的时候勾选上 使用云开发模板(看个人吧,

  • 利用Python制作简易的核酸检测日历

    目录 录入数据 制作日历 1.使用openpyxl创建表格 2.定义表格初始化和单元格设置的函数 3.实现日历 制作一年的日历 我的坐标是深圳,2022年以来,大部分时候要求24小时,少部分时候要求48小时,更少的时候要求72小时,没有更长的情况. 本文根据我的核酸检测记录,制作成日历,将核酸检测记录可视化到日历中. 录入数据 核酸检测记录能查到的最早时间范围是一个月,以前的检测记录没有提前保存,所以先用8月份的数据制作日历. 查询8月份的检测记录,录入到代码中. # coding=utf-8

  • Python一键生成核酸检测日历的操作代码

    目录 UI自动化提取检测记录 生成核酸检测日历 大家好,我是小小明.鉴于深圳最近每天都要做核酸,我觉得有必要用程序生成自己的检测日历,方便查看. 首先我们需要从深i您-自主申报的微信小程序中提取自己的核酸检测记录,然后使用绘图库自动绘制检测日历. UI自动化提取检测记录 首先,我们在PC端微信打开深i您-自主申报微信小程序: 点击 核酸检测记录,再点击自己的姓名即可查看自己的核酸检测记录: 下面我们打开inspect.exe工具分析查看节点: 于是开始编码: import pandas as p

  • 微信小程序 开发之快递查询功能的实现

    微信小程序 快递查询功能: 产品需求, 准备api, 代码编写.  第一步:产品需求,我们需要实现如下图的一个功能,在文本框输入快递单号,点击查询,下面出来我们需要的快递信息 第二步:准备 我们先找一个快递的api接口,通过http://apistore.baidu.com/我们可以看到很多的api,我们找一个快递查询的 我们可以看到有接口地址,和一些参数.做好这个准备接下来就开始编码工作了---- 第三步:编码工作 我们新建一个Express的文件,然后默认文件准备齐全 我们现在app.js中

  • 使用微信小程序制作核酸检测点查询工具

    目录 全国省市区数据 拼接参数调用接口 渲染数据优化细节 出门在外,没有核酸证明寸步难行,此文将教你如何通过小程序制作一个工具帮你在人生地不熟的情况如何迅速找到核酸检测点,实现核酸点查询.地图导航.拨号等功能. 小程序 创建小程序 访问微信公众平台,点击账号注册. 选择小程序,并在表单填写所需的各项信息进行注册. 在开发管理选择开发设置,将AppID及AppSecret复制出来进行存储. 下载安装微信web开发者工具并创建一个新的项目,填入上图所复制的AppId. 申请腾讯地图用户key 访问腾

  • 微信小程序制作表格的方法

    本文实例为大家分享了微信小程序制作表格的具体代码. 微信小程序中没有专门的表格制作工具,不过使用列表渲染可以实现, 下面是我做的表格图片: 方法如下: 在XXX.wxml中填写下面的代码 <view class="table"> <view class="tr bg-w"> <view class="th">参数</view> <view class="th-2">内

  • 微信小程序 云开发模糊查询实现解析

    这篇文章主要介绍了微信小程序 云开发模糊查询实现详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 解释: db.RegExp 从基础库 2.3.2 开始(wx-server-sdk 从 0.0.23 开始),数据库支持正则表达式查询,开发者可以在查询语句中使用 JavaScript 原生正则对象或使用 db.RegExp 方法来构造正则对象然后进行字符串匹配.在查询条件中对一个字段进行正则匹配即要求该字段的值可以被给定的正则表达式匹配 事例:

  • mpvue实现微信小程序快递单号查询代码

    mpvue是什么? mpvue 是一套定位于开发小程序的前端开发框架,其核心目标是提高开发效率,增强开发体验.使用该框架,开发者只需初步了解小程序开发规范.熟悉 Vue.js 基本语法即可上手.框架提供了完整的 Vue.js 开发体验,开发者编写 Vue.js 代码,mpvue 将其解析转换为小程序并确保其正确运行.此外,框架还通过 vue-cli 工具向开发者提供 quick start 示例代码,开发者只需执行一条简单命令,即可获得可运行的项目. mpvue简介点击查看:http://mpv

  • 基于thinkphp5框架实现微信小程序支付 退款 订单查询 退款查询操作

    微信小程序或微信支付相关操作支付退款订单查询退款查询支付成功,进行回调退款成功 进行回调用到的方法 支付 /** * 预支付请求接口(POST) * @param string $openid openid * @param string $body 商品简单描述 * @param string $order_sn 订单编号 * @param string $total_fee 金额 * @return json的数据 */ public function prepay() { tp_log('

  • 利用微信小程序制作属于自己的Icon图标

    目录 前言 1.将你心仪的图标加入购物车 2.将图标添加至项目 3.我的项目 4.将项目下载至本地 5.将字体转换为base64 6.样式文件修改 7.重命名 8.导入样式文件并使用 总结 前言 最近在接手一个微信小程序,发现里面的图标都是使用的image组件,看起来非常别扭,加载也不太顺畅. 就想着看看微信有没有类似自带的图标库可以使用. 有是有,就是太少了,翻来翻去好像也就 8 种,不太够用啊. 官方没有就只能自己做了,还是阿里的iconfont好使,首先你得有iconfont的账号. 1.

  • 微信小程序多表联合查询的实现详解

    目录 一对多表设计 SQL中的关联查询 低码中的表关联 自定义连接器中实现表关联查询 新建连接器 总结 一对一的设计一般不常见,只需要设计到主表中即可,避免增加复杂性.一对多的关系比较常见,一的一方通常作为主表,多的一方通常作为子表.而多对多一般会拆分成两个一对多的关系,这就必须要用中间表进行过渡. 我们本篇介绍的多表查询,侧重在一对多的关系,我们先看一下我们实际的表设计 一对多表设计 我们实现的是文章关注的业务,通常将文章作为主表,而关注信息作为子表.表和表之间要进行关联,常见的设计思路是子表

  • 微信小程序二维码生成工具 weapp-qrcode详解

    微信小程序 - 二维码生成工具 下载:weapp-qrcode.js文件 github:https://github.com/Pudon/weapp-qrcode-base64 在项目中引入 weapp-qrcode.js 文件 js const app = getApp(); const QR = require('../../lib/weapp-qrcode.js'); // 引入 weapp-qrcode Page({ /** * 页面的初始数据 */ data: { QrCodeURL:

  • 一秒学会微信小程序制作table表格

    大家都知道微信小程序自身没有提供表格这个组件,但是今天的项目需求又出现了,所以只能模仿一个了. 效果图: 代码挺简单方便的: wxml: <view class='history-table-wrap'> <view class="table"> <view class="tr"> <view class="th th1">日期</view> <view class="t

随机推荐