<!--index.wxml-->
<view class="container">
<map latitude="{{lat}}"
longitude="{{lon}}"
show-location="{{true}}"
markers="{{markers}}"
bindmarkertap="bindmarkertap"
></map>
</view>
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
lat:'', //维度
lon:'', //经度
markers:[
{
id:50,
latitude:'30.31874',
longitude:'120.1431',
callout:{
content:'呵呵50'
},
},
{
id: 30,
latitude: '30.31874',
longitude: '120.1441',
title: '哈哈30'
},
{
id: 10,
latitude: '30.31884',
longitude: '120.1421',
title: '哈哈10'
},
]
},
onLoad(){
let that = this
wx.getLocation({
type: 'wgs84',
success(res) {
console.log(res)
that.setData({
lat:res.latitude,
lon:res.longitude
})
}
})
},
bindmarkertap(e){
console.log(e.markerId)
this.data.markers.forEach((item)=>{
if (item.id == e.markerId){
wx.openLocation({
latitude: parseFloat(item.latitude),
longitude: parseFloat(item.longitude),
})
}
})
},
})