效果圖如下:
綠色地標固定在中間,移動地圖的時候獲取對應信息。
先定義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) } }) } }) } }
好,完成,這樣就可以簡單的拿取到地圖的中間位置信息了。