location API也就分這里分兩種wx.getLocation(object)獲取當(dāng)前位置和wx.openLocation(object)通過經(jīng)緯度打開內(nèi)置地圖。其中定位獲取位置信息返回參數(shù)是有問題的speed,accuracy這兩個是沒有的。還有一個就是打開內(nèi)置地圖之后再返回會報一個錯誤(Page route錯誤—WAService.js:2 navigateBack 一個不存在的webviewId0)如果有知道的可告知,我找到解決方式也會補(bǔ)充下!
主要屬性:
wx.getLocation(object)獲取當(dāng)前位置

成功之后返回參數(shù)

wx.openLocation(object)打開微信內(nèi)置地圖

這里直接進(jìn)入微信內(nèi)置應(yīng)用,當(dāng)使用導(dǎo)航返回鍵時是內(nèi)部寫的外界無法干預(yù)所以WAService.js:2 navigateBack 一個不存在的webviewId0這個錯估計也帶等小程序修復(fù)吧!!
wxml
-
-
<button id="0" type="primary" bindtap="listenerBtnGetLocation">定位當(dāng)前位置并打開內(nèi)置地
-
js
-
-
-
Page({
-
data:{
-
text:"Page location"
-
},
-
onLoad:function(options){
-
// 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù)
-
},
-
-
/**
-
* 監(jiān)聽定位到當(dāng)前位置
-
*/
-
listenerBtnGetLocation: function() {
-
wx.getLocation({
-
//定位類型 wgs84, gcj02
-
type: 'gcj02',
-
success: function(res) {
-
console.log(res)
-
wx.openLocation({
-
//當(dāng)前經(jīng)緯度
-
latitude: res.latutude,
-
longitude: res.longitude,
-
//縮放級別默認(rèn)28
-
scale: 28,
-
//位置名
-
name: '測試地址',
-
//詳細(xì)地址
-
address: '火星路24號',
-
//成功打印信息
-
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(){
-
// 頁面渲染完成
-
},
-
onShow:function(){
-
// 頁面顯示
-
},
-
onHide:function(){
-
// 頁面隱藏
-
},
-
onUnload:function(){
-
// 頁面關(guān)閉
-
}
|