码迷,mamicode.com
首页 > 微信 > 详细

小程序map显示marker标记点

时间:2020-06-06 19:00:46      阅读:372      评论:0      收藏:0      [点我收藏+]

标签:nload   ges   tca   url   height   car   common   charset   long   

<!--index.wxml-->
<map markers="{{markers}}" show-location></map>

// pages/chooseCart/chooseCart.js
const API = require(‘../request/api.js‘)
const UI = require(‘../../utils/common.js‘)
onLoad: function (options) {
    var that = this;
    that.getCartList();
},
getCartList(){
    var that = this;
    var params = {};
    //请求后端接口获取数据,把参数一次赋值进去(这里我封装了wx.request)
    API.vehicleStatus(params).then(res => {
        console.log(res);
        res.forEach((item,index) => {
          item[‘id‘]     = index + 1;
          item[‘width‘]  = ‘20px‘;
          item[‘height‘] = ‘20px‘;
          item[‘latitude‘] = item.wd;
          item[‘longitude‘] = item.jd;
          item[‘iconPath‘] = ‘/images/hint.png‘;
          item[‘callout‘] = {};
          item[‘callout‘][‘content‘] = item.pos.length > 10 ? item.pos.substring(0,18) + ‘\r\n‘ + item.pos.substring(18,item.pos.length) : item.pos;
          item[‘callout‘][‘bgColor‘] = ‘#fff‘;
          item[‘callout‘][‘padding‘] = ‘5px‘;
          item[‘callout‘][‘borderRadius‘] = ‘2px‘;
          item[‘callout‘][‘borderWidth‘] = ‘1px‘;
          item[‘callout‘][‘borderColor‘] = ‘#fff‘;
        })
        that.setData({
          markers:res,
        })
      })
 },

//common.js
var toast = function toast(title){
  wx.showToast({
    icon:‘none‘,
    title: title,
    duration:2000,
  })
}
var loading = function toast(title) {
  wx.showLoading({
    title: title,
  })
}
module.exports.toast = toast;
module.exports.loading = loading;

//api.js
var request = require(‘./http.js‘);
var api = {
  vehicleStatus: data => { return request(‘vehicleStatus‘, data) },
}
module.exports = api //导出所有请求接口

//http.js
var host = ‘https://www.xxx.com/api/xcx/‘;//请求地址
module.exports = function (url, data, method) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: `${host}/${url}`,
      data: data,
      method: method || ‘GET‘,
      header: {
        ‘Content-Type‘: ‘application/x-www-form-urlencoded;charset=utf-8‘,
      },
      success: function (res) {
        resolve(res.data);
      },
      complete:function(){
        wx.hideLoading();
      },
      fail: reject,
    })
  })
}

 

小程序map显示marker标记点

标签:nload   ges   tca   url   height   car   common   charset   long   

原文地址:https://www.cnblogs.com/pycmsj/p/13055839.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!