缩放视野展示所有经纬度--初始化展示所有经纬度 --小程序 腾讯地图位置服务 示例代码参考

效果:

index.wxml:

<view class="map-view-container">
  <view class="map-view-content">

    <view class="map-container plr20">
      <map class="map" id="map" latitude="{{location.latitude}}" longitude="{{location.longitude}}" scale="{{scale}}" markers="{{markers}}">
      </map>
    </view>
  </view>

</view>

index.wxss:


.map-view-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
  background: #F8F8F7;
  width: 100%;
}
.map-view-content {
  width: 100%;
  background: #FFF;
  padding:20px 0 20px;
  margin-top: 10px; 
}
.map {
  width:100%;
  height:400px;
  position: relative;
}


 index.js:


Page({

  /**
   * 页面的初始数据
   */
  data: {
    scale: 10.5,
    location: {
      latitude: 39.991104,
      longitude: 116.377503,
    },
    markers: [{
      id: 1,
      latitude: 39.953416,
      longitude: 116.480945,
      joinCluster: true,
      width: 24,
      height: 24,
      iconPath:  '../../map/marker/imgs/Marker1_Activated@3x.png'
    },{
      id: 2,
      latitude: 39.984104,
      longitude: 116.407503,
      joinCluster: true,
      width: 24,
      height: 24,
      iconPath:  '../../map/marker/imgs/Marker1_Activated@3x.png'
    },{
      id: 3,
      latitude: 39.908802,
      longitude: 116.497502,
      joinCluster: true,
      width: 24,
      height: 24,
      iconPath:  '../../map/marker/imgs/Marker1_Activated@3x.png'
    },{
      id: 4,
      latitude: 40.040417,
      longitude: 116.373514,
      joinCluster: true,
      width: 24,
      height: 24,
      iconPath:  '../../map/marker/imgs/Marker1_Activated@3x.png'
    },{
      id: 5,
      latitude: 39.953416,
      longitude: 116.380945,
      joinCluster: true,
      width: 24,
      height: 24,
      iconPath:  '../../map/marker/imgs/Marker1_Activated@3x.png'
    },{
      id: 6,
      latitude: 39.984104,
      longitude: 116.307503,
      joinCluster: true,
      width: 24,
      height: 24,
      iconPath:  '../../map/marker/imgs/Marker1_Activated@3x.png'
    },{
      id: 7,
      latitude: 39.908802,
      longitude: 116.397502,
      joinCluster: true,
      width: 24,
      height: 24,
      iconPath:  '../../map/marker/imgs/Marker1_Activated@3x.png'
    },{
      id: 8,
      latitude: 40.040417,
      longitude: 116.273514,
      joinCluster: true,
      width: 24,
      height: 24,
      iconPath:  '../../map/marker/imgs/Marker1_Activated@3x.png'
    }],
    isDisabled: false,
    dialogShow: false,
		link: 'https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html'
  },

  onShow() {
    
    const mapCtx = wx.createMapContext('map', this);
    mapCtx.initMarkerCluster({
      gridSize:30
    });
  },
})

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值