Taro开发微信小程序之初始化地图到当前位置


在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     }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM