• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

小程序map显示marker标记点

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
<!--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,
    })
  })
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
    热门话题
    阅读排行榜

    扫描微信二维码

    查看手机版网站

    随时了解更新最新资讯

    139-2527-9053

    在线客服(服务时间 9:00~18:00)

    在线QQ客服
    地址:深圳市南山区西丽大学城创智工业园
    电邮:jeky_zhao#qq.com
    移动电话:139-2527-9053

    Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap