微信小程序map的使用

小程序简单使用map组件


一、wxml

<view class="map">
<map    
  id="map" 
  style="width: 100%;height: 100%;"
  longitude="{{longitude}}"
  latitude="{{latitude}}"
  markers="{{markers}}"
  scale="{{scale}}"
  show-location
></map>
</view>

二、wxss

.map{
    width: 100vw;
    height: 100vh;
}

三、JS

Page({
    data: {
        longitude:"",   // 中心经度
        latitude:"",    // 中心纬度
        markers:[],     // 标记点
        scale:10        // 缩放级别,取值范围为3-20
    },

    onLoad: function (options) {
        // 获取当前地理位置
        wx.getLocation({
            success:(res)=>{
                let {latitude,longitude} = res;
                this.setData({
                    latitude,
                    longitude
                })
            }
        })
    },

    // 自定义markers
    getMarkers(){
        // 假设请求数据返回 markers
        // ......
        this.setData({
            markers:[{
                joinCluster:true,   // 是否点聚合
                iconPath:"/images/login.png",  // 项目目录下的图片路径
                longitude:131.29, // 经度
                latitude:78.21,  // 纬度
                width:30,  // 标注图标宽度
                height:30, // 标注图标高度
                callout:{  // 标记点上方的气泡窗口
                    content:"文本",  // 文本
                    color:"red",    // 文本颜色
                    fontSize:24,    // 文本大小
                    borderRadius:10, // 边框圆角
                    bgColor:"bule", // 背景色
                    padding:10,    // 文本边缘留白
                    display:"ALWAYS", // 'BYCLICK':点击显示; 'ALWAYS':常显
                    textAlign:"center"//文本对齐方式。有效值: left, right, center
                }
            }]
       })
    }
})
  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值