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