Taro開發小程序移動地圖固定中間獲取地址


效果圖如下:

綠色地標固定在中間,移動地圖的時候獲取對應信息。

先定義map。

     <Map className="location" id={location}
          latitude={this.state.latitude}
          longitude={this.state.longitude}
          markers={this.state.markers}
          scale='16'
          onRegionchange={this.regionchange}
          // controls={this.state.controls}
          show-location
        >
          <CoverView className="coverloc"><CoverImage src={locationpng} className="coverlocpng"></CoverImage></CoverView>
        </Map>

寫對應樣式。

.coverloc {
        z-index: 6;
        margin:auto;
        text-align: center;
        position:absolute;
        left:50%;
        top:50%;
        height: 100px;
        width: 100px;
        .coverlocpng {
            height: 100px;
            width: 100px;
        }
    }

寫對應的移動地圖的函數,需要用到騰訊地圖對微信小程序的支持。

regionchange = (e) => {
    console.log(e)
    let _this = this
    let value
    if (e.type == 'end') {
      this.mapCtx.getCenterLocation({
        success: function (res) {
          qqmapsdk.reverseGeocoder({
            location: {
              latitude: res.latitude,
              longitude: res.longitude
            },
            success: function (resc) {
              console.log(resc)
              value = resc.result.address_component.street_number //address
              Taro.setStorageSync('site', value)
              console.log('地址是:' + vlaue)
            }
          })
        }
      })
    }
  }

好,完成,這樣就可以簡單的拿取到地圖的中間位置信息了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM