微信小程序多点定位marker标点polyline连线

简介: 微信小程序多点定位marker标点polyline连线

成品预览图

上代码:

js

Page({
  data: {
    longitude: '', //地图界面中心的经度
    latitude: '', //地图界面中心的纬度
    lable_num:0,
    markers: [ 
      //标志点的位置 留一个假数据结构给你们
      // {
      //   id: 0,
      //   iconPath: "../../static/images/mall/zuixing-95.png",
      //   latitude: 24.336770948763558,
      //   longitude: 102.53906505304985,
      //   width: 28,
      //   height: 32
      // }
    ],
    polyline: [{
      //连线点 第一个可以为默认的连线点
      points: [ 
      //  {
      //   latitude:'24.1934',
      //   longitude:'102.92849'
      // }, {
      //   latitude:'24.19713438716873',
      //   longitude:'102.9306447535289'
      // }, {
      //   latitude:'24.19586005538885',
      //   longitude:'102.93735297268154'
      // }
    ],
      color:'#8AC349',
      width:10,
      zIndex: 1
    }]
  },
  onLoad: function () {
    var that = this;
    wx.getLocation({
      type: "wgs84",
      success: function (res) {
        var latitude = res.latitude;
        var longitude = res.longitude;
        console.log("当前位置的经纬度为:", res.latitude, res.longitude);
        that.setData({
          latitude: res.latitude,
          longitude: res.longitude,
        })
        //获取到当前经纬度后 渲染第一个连线点=》也就是自己的位置
//  绘制连线 
  var points = [{
    latitude:res.latitude,
    longitude:res.longitude
}];
//使用concat()来把两个数组合拼起来
var points_s = points.concat(that.data.polyline[0].points);
// console.log(points_s);
that.setData({
  'polyline[0].points':points_s
})
      }
    })
  },
  onReady: function () {
  },
  /**
   * 地图放大缩小事件触发
   * @param {*} e 
   */
  bindregionchange(e) {
    console.log('=bindregiοnchange=', e)
  },
  /**
   * 点击地图事件,有经纬度信息返回
   * @param {*} e 
   */
  bindtapMap(e) {
    let that=this;
    console.log('=bindtapMap=', e)
    console.log('lat'+e.detail.latitude)
    console.log('long'+e.detail.longitude)
    //绘制坐标点
    var insert = [{
        id: parseInt(that.data.lable_num)+1,
        iconPath: "../../static/images/mall/zuixing-95.png",
        latitude: e.detail.latitude,
        longitude: e.detail.longitude,
        width: 30,
        height: 30
    }];
    //使用concat()来把两个数组合拼起来
    var markers_s = insert.concat(that.data.markers);
    that.setData({
      markers:markers_s
    })
  //  绘制连线 
  var points = [{
    latitude:e.detail.latitude,
    longitude:e.detail.longitude
}];
//使用concat()来把两个数组合拼起来
var points_s = points.concat(that.data.polyline[0].points);
// console.log(points_s);
that.setData({
  'polyline[0].points':points_s
})
 //使用concat()来把两个数组合拼起来
//  var points_ = points.concat(that.data.polyline.points);
//  that.setData({
//   'polyline.points':points_
//  })
      //标点+1
    that.setData({
      lable_num:parseInt(that.data.lable_num)+1
    })
  }
})


相关文章
|
6天前
|
小程序 定位技术 Android开发
小程序质量提升丨定位问题解决方案(错误码11)
小程序质量提升丨定位问题解决方案(错误码11)
36 0
|
10月前
|
移动开发 小程序 JavaScript
微信小程序学习实录6(百度经纬度采集、手动调整精度、H5嵌入小程序、百度地图jsAPI、实时定位、H5更新自动刷新)
微信小程序学习实录6(百度经纬度采集、手动调整精度、H5嵌入小程序、百度地图jsAPI、实时定位、H5更新自动刷新)
150 1
|
8月前
|
小程序
uniapp小程序定位 配置permission失败问题
uniapp小程序定位 配置permission失败问题
|
10月前
|
移动开发 小程序 前端开发
浅谈微信小程序的功能定位和使用场景
浅谈微信小程序的功能定位和使用场景
232 0
|
10月前
|
小程序 JavaScript 前端开发
微信小程序 地图选点 获取用户选择的定位信息 wx.chooseLocation
微信小程序 地图选点 获取用户选择的定位信息 wx.chooseLocation
350 0
|
11月前
|
JavaScript 小程序
微信小程序精准定位百度
微信小程序精准定位百度
83 0
|
11月前
|
小程序 前端开发 容器
小程序布局中相对定位的用法
小程序布局中相对定位的用法
|
JavaScript 小程序 定位技术
uniApp微信小程序之——获取腾讯地图的定位功能以及解决uni-app提示getLocation 需要在app.json中生命permission字段的方法
获取腾讯地图的定位功能以及解决uni-app提示getLocation 需要在app.json中生命permission字段的方法
544 0
|
小程序
微信小程序也可以实现定位打卡/签到打卡了(附源码)
本篇文章带你实现实时定位功能:包括实时定位监听、定位权限判断、经纬度间距计算、判断当前位置是否在目的地的范围区间。
3021 2
|
小程序 JavaScript 前端开发

热门文章

最新文章