微信小程序——地图(定位,多个标记点)

效果图

在这里插入图片描述

指定为位置

Page({
  data: {
    longitude: 113.14278, //地图界面中心的经度
    latitude: 23.02882, //地图界面中心的纬度
    markers: [ //标志点的位置
      //位置0
      {
        id: 0,
        iconPath: "../images/1.png",
        latitude: 23.04308268848755,
        longitude: 113.13562655285273,
        width: 28,
        height: 32
      },
      //位置1
      {
        id: 1,
        iconPath: "../images/1.png",
        latitude: 23.03814334110172,
        longitude: 113.15378758608608,
        width: 28,
        height: 32
      },
      //位置2
      {
        id: 2,
        iconPath: "../images/1.png",
        latitude: 23.03377135768493,
        longitude: 113.17075479351229,
        width: 28,
        height: 32
      },
      //位置3
      {
        id: 3,
        iconPath: "../images/1.png",
        latitude: 23.02542516569787,
        longitude: 113.1417505798413,
        width: 28,
        height: 32
      },
      //位置4
      {
        id: 4,
        iconPath: "../images/1.png",
        latitude: 23.022740816325694,
        longitude: 113.14681189547798,
        width: 28,
        height: 32
      },
    ]
  },

  onLoad: function () {

  },
  onReady: function () {

  },

  /**
   * 地图放大缩小事件触发
   * @param {*} e 
   */
  bindregionchange(e) {
    console.log('=bindregiοnchange=', e)
  },

  /**
   * 点击地图事件,有经纬度信息返回
   * @param {*} e 
   */
  bindtapMap(e) {
    console.log('=bindtapMap=', e)
  }
})

page{
  height: 100%;
}

<view class="" hover-class="none" hover-stop-propagation="false" style="width: 100%; height: 100%;">

  <map id="map" longitude="{{longitude}}" latitude=" {{latitude}}" markers="{{markers}}" scale="14" show-location
    style="width: 100%; height: 100%;" bindregionchange="bindregionchange" bindtap="bindtapMap"></map>

</view>

图标 1.png
在这里插入图片描述

示例2:

Page({
  data: {
    latitude: 23.04308268848755, //地图界面中心的纬度
    longitude: 113.13562655285273, //地图界面中心的经度

    // markers: [ //标志点的位置
    //   //位置0
    //   {
    //     id: 0,
    //     iconPath: "../images/1.png",
    //     latitude: 23.04308268848755,
    //     longitude: 113.13562655285273,
    //     width: 28,
    //     height: 32
    //   },
    //   //位置1
    //   {
    //     id: 1,
    //     iconPath: "../images/1.png",
    //     latitude: 23.03814334110172,
    //     longitude: 113.15378758608608,
    //     width: 28,
    //     height: 32
    //   },
    //   //位置2
    //   {
    //     id: 2,
    //     iconPath: "../images/1.png",
    //     latitude: 23.03377135768493,
    //     longitude: 113.17075479351229,
    //     width: 28,
    //     height: 32
    //   },
    //   //位置3
    //   {
    //     id: 3,
    //     iconPath: "../images/1.png",
    //     latitude: 23.02542516569787,
    //     longitude: 113.1417505798413,
    //     width: 28,
    //     height: 32
    //   },
    //   //位置4
    //   {
    //     id: 4,
    //     iconPath: "../images/1.png",
    //     latitude: 23.022740816325694,
    //     longitude: 113.14681189547798,
    //     width: 28,
    //     height: 32
    //   },
    // ]

    markers: []

  },

       //定义js函数对象方法
mapPoint(id,iconPath,latitude,longitude,width,height) {
      return {"id":id,
              "iconPath":iconPath,  
              "latitude":latitude,
              "longitude":longitude,  
              "width":width,
              "height":height
               };     
     },
  
  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);
        var newArray1 = new Array();

        //  newArray1.push(  {
        //   id: 0,
        //   iconPath: "../images/1.png",
        //   latitude: 23.04308268848755,
        //   longitude: 113.13562655285273,
        //   width: 28,
        //   height: 32
        // });
        // newArray1.push(  {
        //   id: 1,
        //   iconPath: "../images/1.png",
        //   latitude: 23.03814334110172,
        //   longitude: 113.15378758608608,
        //   width: 28,
        //   height: 32
        // });
        // newArray1.push({"id":2,
        // "iconPath":"../images/1.png",  
        // "latitude": res.latitude - 0.001,
        // "longitude":res.longitude - 0.002,  
        // "width":28,
        // "height":32
        //  });

         console.log("newArray1:",newArray1);
        for(var i =0; i<5 ;i++) {
          newArray1.push({"id":i,
          "iconPath":"../images/1.png",  
          "latitude": res.latitude - 0.001*i,
          "longitude":res.longitude - 0.001*i,  
          "width":28,
          "height":32
           })
        };
        that.setData({
          latitude: res.latitude,
          longitude: res.longitude,
          markers: newArray1,
        })

    
      }
    })
  },
  onReady: function () {

  },

  /**
   * 地图放大缩小事件触发
   * @param {*} e 
   */
  bindregionchange(e) {
    console.log('=bindregiοnchange=', e)
  },

  /**
   * 点击地图事件,有经纬度信息返回
   * @param {*} e 
   */
  bindtapMap(e) {
    console.log('=bindtapMap=', e)
  }
})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值