zoukankan      html  css  js  c++  java
  • 根据后台数据,渲染多个坐标在小程序中

    1、根据后台数据,返回的经纬度,渲染到地图上

    2、点击各个坐标点,显示公司一些详细信息

    3、如下图所示,这个接口目前是有效的,如果无效的话,可以自己写一个json文件自测一些哈

     以下是自己写的一个demo,以供参考;详细的可以看看微信小程序的文档,弄懂了就好,知识万变不离其宗,努力吧

    wxml文件

     1 <map 
     2   id="map" 
     3   longitude="{{longitude}}" 
     4   latitude="{{latitude}}" 
     5   scale="5" 
     6   controls="{{controls}}" 
     7   bindcontroltap="controltap" 
     8   markers="{{markers}}" 
     9   polyline="{{polyline}}" 
    10   bindregionchange="regionchange" 
    11   show-location 
    12   style=" 100%; height: 100%;">
    13 </map>

    wxss文件

    map{
      height: 100%;
    }
    page{
      height: 100%;
    }
    

     js文件

    // 地图标记点
    var markers = []
    // 地图标记点的气泡
    var callout = []
    
    Page({
    
      /**
       * 页面的初始数据
       */
      data: {
        marker_latitude: '',
        marker_longitude: ''
      },
    
      /**
       * 生命周期函数--监听页面加载
       */
      onLoad: function (options) {
        var that = this
        wx.request({
          url: 'http://101.200.182.221:8001/Api/Services/GetAllServiceFacilitatorMap',
          data: {},
          method: 'POST',
          header: {
            'content-type': 'application/json' // 默认值
          },
          success: (res) => {
            // console.log(res.data.Data)
            that.setData({
              listData: res.data.Data
            })
    
            var listData = res.data.Data
            for (var i = 0; i < listData.length; i++) {
              markers = markers.concat({
                iconPath: "../../image/location.png",
                id: listData[i].FacilitatorId,
                callout: {
                  content: listData[i].Contact + '
    ' + listData[i].FacilitatorName + '
    ' + listData[i].Address,
                  fontSize: '16',
                  padding: true,
                  color: '#444',
                  display: 'BYCLICK',
                  textAlign: 'center',
                  borderRadius: 15
                },
                latitude: listData[i].Latitude,
                longitude: listData[i].Longitude,
                 20,
                height: 20
              })
            }
            // console.log(markers)
            that.setData({
              markers: markers,
              latitude: listData[0].Latitude,
              longitude: listData[0].Longitude
            })
    
            wx.getLocation({
              type: 'wgs84',
              success: (res) => {
                var latitude = res.latitude
                var longitude = res.longitude
              },
            })
          }
        })
      },
    
      /**
       * 生命周期函数--监听页面初次渲染完成
       */
      onReady: function () {
    
      },
    
      /**
       * 生命周期函数--监听页面显示
       */
      onShow: function () {
    
      },
    
      regionchange(e) {
        console.log(e.type)
      },
      // markertap(e){
      //   var that = this
      //   console.log(e.markerId)
      //   for(var i=0;i<this.data.listData.length;i++){
      //     if(e.markerId == this.data.listData[i].id){
      //       this.setData({
      //         marker_latitude:this.data.listData[i].Latitude,
      //         marker_longitude:this.data.listData[i].Longitude,
      //         title: this.data.listData[i].FacilitatorName
      //       })
      //     }
      //   }
    
      //   wx.openLocation({
      //     latitude: Number(that.data.marker_latitude),
      //     longitude:Number(that.data.marker_longitude),
      //     name:that.data.title,
      //     scale:6
      //   })
      // },
    
      controltap(e) {
        console.log(e.controlId)
      },
    
      /**
       * 生命周期函数--监听页面隐藏
       */
      onHide: function () {
    
      },
    
      /**
       * 生命周期函数--监听页面卸载
       */
      onUnload: function () {
    
      },
    
      /**
       * 页面相关事件处理函数--监听用户下拉动作
       */
      onPullDownRefresh: function () {
    
      },
    
      /**
       * 页面上拉触底事件的处理函数
       */
      onReachBottom: function () {
    
      },
    
      /**
       * 用户点击右上角分享
       */
      onShareAppMessage: function () {
    
      }
    })
  • 相关阅读:
    MyBatis 延迟加载
    超经典的 25 道 MyBatis 面试题
    公钥与私钥,HTTPS详解
    分布式,集群,微服务的理解
    单例模式的饿汉式和懒汉式的实现以及比较它们的区别比较(Java实现)
    Mybatis的一级缓存和二级缓存详解
    Maven install没有将jar包加载到本地仓库
    Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
    数据结构_C语言_单链表
    Java实现一个简单的LRUCache
  • 原文地址:https://www.cnblogs.com/m1754171640/p/10511129.html
Copyright © 2011-2022 走看看