uniapp 小程序 腾讯地如何点连线,线成面,并且标注两点间的距离

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
1. 引入地图组件 在 `pages.json` 中引入地图组件,例如: ``` "usingComponents": { "map": "@vant/weapp/mapp", } ``` 2. 在页面中添加地图组件 在页面中添加 `map` 组件,并设置属性 `show-location` 为 `true`,表示显示当前位置。 ``` <map show-location="{{true}}" /> ``` 3. 添加打 在页面中添加打,可以使用 `map` 组件的 `markers` 属性。例如: ``` <map show-location="{{true}}" markers="{{markers}}" /> ``` 其中 `markers` 是一个数组,每个数组元素表示一个打对象,包含以下属性: - `id`:打的唯一标识,必须是字符串类型。 - `latitude`:打的纬度。 - `longitude`:打的经度。 - `title`:打的标题。 - `iconPath`:打的图标路径。 - `width`:打的宽度。 - `height`:打的高度。 例如: ``` markers: [ { id: '1', latitude: 30.123456, longitude: 120.123456, title: '打1', iconPath: '/static/images/marker.png', width: 32, height: 32, }, { id: '2', latitude: 30.234567, longitude: 120.234567, title: '打2', iconPath: '/static/images/marker.png', width: 32, height: 32, }, ], ``` 4. 实现击打弹窗功能 可以使用 `map` 组件的 `bindmarkertap` 事件来实现击打弹窗功能。例如: ``` <map show-location="{{true}}" markers="{{markers}}" bindmarkertap="onMarkerTap" /> onMarkerTap(event) { const markerId = event.markerId; const marker = this.data.markers.find(marker => marker.id === markerId); wx.showModal({ title: marker.title, content: `纬度:${marker.latitude},经度:${marker.longitude}`, }); }, ``` 在 `onMarkerTap` 方法中,通过 `event.markerId` 获取击的打的 `id`,然后通过 `this.data.markers.find` 方法找到对应的打对象。最后使用 `wx.showModal` 方法弹出弹窗,显示的标题和经纬度信息。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值