1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 微信小程序使用腾讯地图

微信小程序使用腾讯地图

时间:2021-04-04 10:06:48

相关推荐

微信小程序使用腾讯地图

第一步:设置起始跳转页

在wxml里面设置view控件

<view bindtap="toMap" data-address="{{address}}"><text>跳转到地图</text></view>

js里面设置跳转的值

Page({data: {address:"成都市"},onLoad: function (options) {},toMap(e) {wx.navigateTo({url: '/pages/map/map?address=' + e.currentTarget.dataset.address,})}})

第二步:跳转后对值进行处理

Page({data: {latitude: "",longitude: "",markers: [{id: 1,latitude: "",longitude: "",}]},onLoad: function(options) {var address = options.address;console.log(address);this.getLocation(address);},getLocation(address) {var that = this;wx.request({url: 'https://apis./ws/geocoder/v1/',method: 'get',data: {key: "", //这里的key要在腾讯地图上面申请address: address},success(res) {console.log(res);that.setData({latitude: res.data.result.location.lat,longitude: res.data.result.location.lng,"markers[0]": {latitude: res.data.result.location.lat,longitude: res.data.result.location.lng}})},fail(err) {console.log(err);}})}})

设置map控件的高度,长度以及值(markers是设置显示自己的位置)

效果图

点击跳转到地图

跳转成功

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。