目前很多微信小程序都具备地图查看的功能,那么对于在微信小程序中如何实现地图插件的调用方法,可能很多初学小程序开发的技术人员还存在很多疑问,那么下面就来跟大家详细解答一下。
首先肯定是借助小程序自带的map组件 .wxml代码:
<map id="myMap" style="width: 100%; height: 300px;" latitude="{{latitude}}" longitude="{{longitude}}" markers="{{markers}}" polyline="{{polyline}}" show-location bindmarkertap="selectMarket" include-points="{{markers}}" show-location="true"></map>
首先我们要创建一个画布 .js
onReady: function (e) {
this.mapCtx = wx.createMapContext('myMap');
}
要去后台接收数据,在markers里然后放入data在前台展示数据
在js中写入事件代码
selectMarket(e) {
//console.log(e)
var that = this;
that.setData({
uid: e.markerId
})
wx.getLocation({//获取当前经纬度
type: 'wgs84', //返回可以用于wx.openLocation的经纬度,官方提示bug: iOS 6.3.30 type 参数不生效,只会返回 wgs84 类型的坐标信息
success: function (res) {
var url = getApp().data.servsers;
var uid = that.data.uid
//console.log(uid)
wx.request({
url: url + 'Index/nav_data?uid=' + uid,
success: function (data) {
console.log(data)
wx.openLocation({//使用微信内置地图查看位置。
latitude: Number(data.data.latitude),//要去的纬度-地址
longitude: Number(data.data.longitude),//要去的经度-地址
name: data.data.name,
address: data.data.address
})
}
})
}
})
}
})
操作完毕。点击标注之后跳到微信内置地图实现导航,整个步骤流程是不是看起来非常的简单,但是操作起来并非如此,大家一定要一步一步来,好了如果还存在有疑问的话,可以留言咨询。
本文由专业的微信小程序开发公司燚轩科技整理发布,原创不易,如需转载,请注明出处!