小程序周边厕所

index.wxml文件如下,markers标点

 
 
  1. <map  id="map" longitude="{{jd}}" latitude="{{wd}}"  
     

  2. markers="{{markers}}" style="width: 100%; height: 1000rpx;"  show-location></map>

index.js文件如下,仍使用上一节的腾讯sdk,在获取当前地理位置后,利用腾讯sdk的search方法查找周边厕所,返回数组数据。选取5个标点进行赋值。


  1. var QQMapWX = require('../libs/qqmap-wx-jssdk.js');

  2. var qqmapsdk;

  3. var latitude1, longitude1;

  4. var getdata = [];

  5. Page({

  6.  data: {

  7.  },

  8.  onLoad: function (options) {

  9.    qqmapsdk = new QQMapWX({

  10.      key: '22VBZ-REEK5-WVSI7-QKCOP-QPM6E-W7BPO'

  11.    });

  12.  },

  13.  onReady: function () {

  14.    var that = this

  15.    wx.getLocation({

  16.      type: 'wgs84',

  17.      success: function (res) {

  18.        console.log(res)

  19.        latitude1 = res.latitude

  20.        longitude1 = res.longitude

  21.        qqmapsdk.search({

  22.          location: {

  23.            latitude: latitude1,

  24.            longitude: longitude1

  25.          },

  26.          keyword: '厕所',

  27.          success: function (res) {

  28.            console.log(res.data);

  29.            console.log(res.data[0].location.lat);

  30.            getdata = res.data

  31.            that.setData({

  32.              wd: latitude1,

  33.              jd: longitude1,

  34.              markers: [

  35.                {

  36.                  iconPath: "../libs/w.jpg",

  37.                  id: 0,

  38.                  latitude: getdata[0].location.lat,

  39.                  longitude: getdata[0].location.lng

  40.                },

  41.                {

  42.                  iconPath: "../libs/w.jpg",

  43.                  id: 1,

  44.                  latitude: getdata[1].location.lat,

  45.                  longitude: getdata[1].location.lng

  46.                },

  47.                {

  48.                  iconPath: "../libs/w.jpg",

  49.                  id: 2,

  50.                  latitude: getdata[2].location.lat,

  51.                  longitude: getdata[2].location.lng

  52.                },

  53.                {

  54.                  iconPath: "../libs/w.jpg",

  55.                  id: 3,

  56.                  latitude: getdata[3].location.lat,

  57.                  longitude: getdata[3].location.lng

  58.                },

  59.                {

  60.                  iconPath: "../libs/w.jpg",

  61.                  id: 4,

  62.                  latitude: getdata[4].location.lat,

  63.                  longitude: getdata[4].location.lng

  64.                },

  65.              ]

  66.            })

  67.          }

  68.        });

  69.      }

  70.    })

  71.  },

  72. })

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值