location API也就分這里分兩種wx.getLocation(object)獲取當(dāng)前位置和wx.openLocation(object)通過(guò)經(jīng)緯度打開(kāi)內(nèi)置地圖。其中定位獲取位置信息返回參數(shù)是有問(wèn)題的speed,accuracy這兩個(gè)是沒(méi)有的。還有一個(gè)就是打開(kāi)內(nèi)置地圖之后再返回會(huì)報(bào)一個(gè)錯(cuò)誤(Page route錯(cuò)誤―WAService.js:2 navigateBack 一個(gè)不存在的webviewId0)如果有知道的可告知,我找到解決方式也會(huì)補(bǔ)充下!
主要屬性:
wx.getLocation(object)獲取當(dāng)前位置
成功之后返回參數(shù)
wx.openLocation(object)打開(kāi)微信內(nèi)置地圖
這里直接進(jìn)入微信內(nèi)置應(yīng)用,當(dāng)使用導(dǎo)航返回鍵時(shí)是內(nèi)部寫(xiě)的外界無(wú)法干預(yù)所以WAService.js:2 navigateBack 一個(gè)不存在的webviewId0這個(gè)錯(cuò)估計(jì)也帶等小程序修復(fù)吧!!
wxml
<button id="0" type="primary" bindtap="listenerBtnGetLocation">定位當(dāng)前位置并打開(kāi)內(nèi)置地圖</button>
js
Page({ data:{ text:"Page location" }, onLoad:function(options){ // 頁(yè)面初始化 options為頁(yè)面跳轉(zhuǎn)所帶來(lái)的參數(shù) }, /** * 監(jiān)聽(tīng)定位到當(dāng)前位置 */ listenerBtnGetLocation: function() { wx.getLocation({ //定位類(lèi)型 wgs84, gcj02 type: 'gcj02', success: function(res) { console.log(res) wx.openLocation({ //當(dāng)前經(jīng)緯度 latitude: res.latutude, longitude: res.longitude, //縮放級(jí)別默認(rèn)28 scale: 28, //位置名 name: '測(cè)試地址', //詳細(xì)地址 address: '火星路24號(hào)', //成功打印信息 success: function(res) { console.log(res) }, //失敗打印信息 fail: function(err) { console.log(err) }, //完成打印信息 complete: function(info){ console.log(info) }, }) }, fail: function(err) { console.log(err) }, complete: function(info) { console.log(info) }, }) }, onReady:function(){ // 頁(yè)面渲染完成 }, onShow:function(){ // 頁(yè)面顯示 }, onHide:function(){ // 頁(yè)面隱藏 }, onUnload:function(){ // 頁(yè)面關(guān)閉 }})
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注