//wxml
<view class="container">
<block wx:if="{{position}}">
<web-view src="https://wechat.sghcloud.com"></web-view>
</block>
</view>
//js
const app = getApp()
Page({
data: {
position: false
},
onLoad: function () {
wx.getLocation({
type: 'wgs84',
success: function (res) {
var latitude = res.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy
console.log(latitude, longitude)
if (latitude > 22 && latitude < 23 && longitude > 112.028 ) {
this.setData({
position: true
})
} else {
this.setData({
position: true
})
wx.showLoading({
title: '等待中',
})
}
}
})
},
})
首先: 没有写过小程序
原因是回调里面的this指向变了
解决