国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

uniapp小程序拖動地圖,標記物固定地圖中心不動,展示拖動后的位置信息

這篇具有很好參考價值的文章主要介紹了uniapp小程序拖動地圖,標記物固定地圖中心不動,展示拖動后的位置信息。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

思路:將標記物固定在地圖正中間,地圖拖動結束后,獲取地圖中心位置的經(jīng)緯度信息

html代碼

<view style="width: 100%;height: 60vh;posotion: relative">
      <map id="map" style="width: 100%;height: 60vh;" :latitude="latitude" :longitude="longitude" show-location @regionchange="regionchange"></map>
        <image :src="addrType=='load'?'../../static/choose/load.png':'../../static/choose/unload.png'" mode="aspectFill" class="position-logo"></image>
        <view class="addr-info">
          <view class="addr-info-text">{{addr}}</view>
          <view class="triple"></view>
       </view>
    </view>

css代碼

.position-logo {
    position: absolute;
    width: 77rpx;
    height: 77rpx;
    top: calc(30vh - 35rpx);
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .addr-info {
    padding: 19rpx 26rpx;
    background-color: rgba(0, 0, 0, 0.66);
    box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.66);
    opacity: 0.8;
    border-radius: 12rpx;
    position: absolute;
    top: calc(30vh - 130rpx);
    left: 50%;
    transform: translate(-50%, -50%);
    white-space: nowrap;
    .addr-info-text {
      font-size: 30rpx;
      font-weight: 500;
      color: #FFFFFF;
    }
    .triple {
      position: absolute;
      width: 0%;
      height: 0%;
      border: 15rpx solid transparent;
      border-top-color: rgba(0, 0, 0, 0.66);
      opacity: 0.8;
      bottom: -29rpx;
      left: 50%;
      transform: translateX(-50%);
    }
  }

js代碼

(小程序解析經(jīng)緯度獲取地址信息需申請騰訊地圖key并下載SDK文件)文章來源地址http://www.zghlxwxcb.cn/news/detail-630979.html

const QQMapWX = require('@/common/qqmap-wx-jssdk.js');  // 引入sdk文件

// 頁面加載時創(chuàng)建并使用
onLoad(){
  this.qqMapSdk = new QQMapWX({key: 'xxxxxxx'}); // 需填入申請的key
}

// 獲取中心點位置
      getCenterLatLong(){
        let mapCtx = uni.createMapContext('map', this)
        mapCtx.getCenterLocation({
          success: (res) => {
            this.latitude = res.latitude
            this.longitude = res.longitude
            this.formatLocation(res.latitude, res.longitude)
            this.$forceUpdate()
          },
          fail: (res) => {
            console.log('失敗',res)
          }
        })
      },
      // 轉換城市
      formatLocation(latitude, longitude) {
        this.qqMapSdk.reverseGeocoder({
          location: {
            latitude,
            longitude
          },
          success: (res) => {
            this.addr = res.result.address_reference.landmark_l2.title
            this.address = res.result.address
          }
        })
      },
      // 地圖區(qū)域發(fā)生改變
      regionchange(e){
        if(e.type==='end'){
          this.getCenterLatLong()
        }
      },

到了這里,關于uniapp小程序拖動地圖,標記物固定地圖中心不動,展示拖動后的位置信息的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包