小程序周边厕所

来源:互联网 发布:微信玩骰子作弊软件 编辑:程序博客网 时间:2024/03/28 19:23

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. varQQMapWX= 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 =newQQMapWX({

  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. })

原创粉丝点击