在componentDidMount中,初始化mapCtx。
let _this = this
this.mapCtx = Taro.createMapContext('container') //container是地图显示模块id
Taro.getLocation({
type: 'wgs84',
success(res) {
_this.setState({
latitude = res.latitude,
longitude = res.longitude
})
}
})
//移动到定位到的位置 this.mapCtx.moveToLocation()
注意:定位要配置app.js下的config,添加permission
1 "permission": { 2 "scope.userLocation": { 3 "desc": "你的位置信息将用于小程序位置接口的效果展示" 4 } 5 }