小程序地图开发点击标记点跳转第三方地图

<!--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),

})

}

})

},

})

 

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值