<noframes id="bhrfl"><address id="bhrfl"></address>

    <address id="bhrfl"></address>

    <noframes id="bhrfl"><address id="bhrfl"><th id="bhrfl"></th></address>

    <form id="bhrfl"><th id="bhrfl"><progress id="bhrfl"></progress></th></form>

    <em id="bhrfl"><span id="bhrfl"></span></em>

    全部
    常見問題
    產品動態
    精選推薦

    高德地圖實現點擊地圖添加標記,通過輸入框搜索詳細地址自動定位到指定位置

    管理 管理 編輯 刪除

    高德地圖api版本:JavaScript API V2.0.05dd9320230727101316981.png

    用高德地圖實現輸入搜索地址 添加標記,鼠標移動標記來獲取當前該點的經緯度,詳細地址

    1. 高德地圖的頁面構建:首先先引入高德地圖,增加自己想要的功能,我們這里需要一個輸入聯想框

    944ba202307271017038938.png

    2. 高德地圖的Api來實現相關功能

    1. 構建地圖

      initMap() {
          const that = this
          return new Promise((reslove, reject) => {
            AMapLoader.load({
              key: 'cf5c437b14780406af75a81b380cafac',
              version: '2.0',
              plugins: [
                'AMap.ToolBar',
                'AMap.Scale',
                'AMap.Geocoder',
                'AMap.Geolocation',
                'AMap.PlaceSearch',
                'AMap.AutoComplete',
                'AMap.CitySearch'
              ],
              resizeEnable: true
            }).then((AMap) => {
              that.map = new AMap.Map('allmap', {
                resizeEnable: true,
                zoom: 14,
                viewMode: '3D', //使用3D視圖
                center: [that.positionInfo.lng, that.positionInfo.lat]
              })
              that.getCurrentLocation()
              that.map.addControl(new AMap.Scale()) // 在圖面添加比例尺控件,展示地圖在當前層級和緯度下的比例尺
              that.map.addControl(new AMap.ToolBar()) //在圖面添加鷹眼控件,在地圖右下角顯示地圖的縮略圖
              that.geocoder = new AMap.Geocoder({ radius: 1000, extensions: 'all', city: '全國' })
              that.mapSearchInit()
              that.geocoder.getAddress([that.positionInfo.lng, that.positionInfo.lat], function (status, result) {
                if (status === 'complete' && result.regeocode) {
                  that.address = result.regeocode.formattedAddress
                } else {
                  that.$message.error('根據經緯度查詢地址失敗')
                }
              })
            })
          })
        },


    2. 根據輸入框內容搜索地點,經緯度

      searchKeyWord() {
          let that = this
          that.placeSearchComponent.search(that.address, function (status, result) {
            if (status === 'complete' && result.info === 'OK') {
              that.show = true
              // 關鍵字聯想的選項內容
              that.poiList = result.poiList.pois
            } else {
              that.showsearchResult = false
              that.poiList = []
              that.$message({
                message: '沒有查到結果',
                type: 'warning'
              })
            }
          })
        },

    3. 動態設置點標記,構造矢量圓形

     dynamicSign(lng, lat, radius) {
          var marker = new AMap.Marker({
            position: new AMap.LngLat(lng, lat), //參數為經緯度
            draggable: true,
            cursor: 'move',
            riseOnHover: true,
            bubble: true,
            cursor: 'pointer'
          })
          // 構造矢量圓形
          const circle = new AMap.Circle({
            center: new AMap.LngLat(lng, lat), // 圓心位置
            radius: radius, //半徑
            strokeColor: '#1890ff', //線顏色
            strokeOpacity: 1, //線透明度
            strokeWeight: 1, //線粗細度
            fillColor: '#1890ff', //填充顏色
            fillOpacity: 0.35 //填充透明度
          })
          this.map.clearMap()
          this.map.add([marker, circle]) // 添加點標志
          marker.on('dragend', this.markerClick)
        },

     高德地圖api接口比較豐富,大多的需求都能實現。本次主要使用了POI搜索插件AMap.PlaceSearch,獲取城市信息AMap.getCityInfo,設置標記點AMap.Marker,構造矢量圖AMap.Circle結合了帶列表的POI搜索的這個,再將監聽事件改為列表點選的selectChange事件,獲得當前點選地點經緯度,這樣將二者進行了組合一下實現了以上的搜索以及展現方式。


    請登錄后查看

    怎么網名又被占用了 最后編輯于2023-07-27 10:34:20

    快捷回復
    回復
    回復
    回復({{post_count}}) {{!is_user ? '我的回復' :'全部回復'}}
    排序 默認正序 回復倒序 點贊倒序

    {{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level }}

    作者 管理員 企業

    {{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
    {{item.is_suggest == 1? '取消推薦': '推薦'}}
    沙發 板凳 地板 {{item.floor}}#
    {{item.user_info.title || '暫無簡介'}}
    附件

    {{itemf.name}}

    {{item.created_at}}  {{item.ip_address}}
    打賞
    已打賞¥{{item.reward_price}}
    {{item.like_count}}
    {{item.showReply ? '取消回復' : '回復'}}
    刪除
    回復
    回復

    {{itemc.user_info.nickname}}

    {{itemc.user_name}}

    回復 {{itemc.comment_user_info.nickname}}

    附件

    {{itemf.name}}

    {{itemc.created_at}}
    打賞
    已打賞¥{{itemc.reward_price}}
    {{itemc.like_count}}
    {{itemc.showReply ? '取消回復' : '回復'}}
    刪除
    回復
    回復
    查看更多
    打賞
    已打賞¥{{reward_price}}
    8380
    {{like_count}}
    {{collect_count}}
    添加回復 ({{post_count}})

    相關推薦

    快速安全登錄

    使用微信掃碼登錄
    {{item.label}} 加精
    {{item.label}} {{item.label}} 板塊推薦 常見問題 產品動態 精選推薦 首頁頭條 首頁動態 首頁推薦
    取 消 確 定
    回復
    回復
    問題:
    問題自動獲取的帖子內容,不準確時需要手動修改. [獲取答案]
    答案:
    提交
    bug 需求 取 消 確 定
    打賞金額
    當前余額:¥{{rewardUserInfo.reward_price}}
    {{item.price}}元
    請輸入 0.1-{{reward_max_price}} 范圍內的數值
    打賞成功
    ¥{{price}}
    完成 確認打賞

    微信登錄/注冊

    切換手機號登錄

    {{ bind_phone ? '綁定手機' : '手機登錄'}}

    {{codeText}}
    切換微信登錄/注冊
    暫不綁定
    亚洲欧美字幕
    CRMEB客服

    CRMEB咨詢熱線 咨詢熱線

    400-8888-794

    微信掃碼咨詢

    CRMEB開源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
    返回頂部 返回頂部
    CRMEB客服