本文實(shí)例講述了微信小程序?qū)崿F(xiàn)打開內(nèi)置地圖功能。分享給大家供大家參考,具體如下:
1、效果展示

2、關(guān)鍵代碼
index.wxml布局文件代碼
<button type="default" bindtap="openMap">打開地圖</button>
index.js邏輯文件代碼
Page({ openMap:function(){ wx.getLocation({ type: 'gcj02', // 默認(rèn)為 wgs84 返回 gps 坐標(biāo),gcj02 返回可用于 wx.openLocation 的坐標(biāo) success: function(res){ // success wx.openLocation({ latitude: res.latitude, // 緯度,范圍為-90~90,負(fù)數(shù)表示南緯 longitude: res.longitude, // 經(jīng)度,范圍為-180~180,負(fù)數(shù)表示西經(jīng) scale: 28, // 縮放比例 }) } }) }})這里bindtap="openMap"綁定的openMap函數(shù)中調(diào)用wx.openLocation函數(shù)獲取本機(jī)經(jīng)緯度信息。
更多關(guān)于wx.openLocation函數(shù)詳細(xì)介紹可參考官網(wǎng) https://mp.weixin.qq.com/debug/wxadoc/dev/api/location.html
3、源代碼點(diǎn)擊此處本站下載。
希望本文所述對大家微信小程序開發(fā)有所幫助。
新聞熱點(diǎn)
疑難解答