• vue中使用baidu-map获取当前坐标。


    1.安装iview

      $npm install iview --save

      在main.js中引入

      

      这样就算安装完成了!

    2.安装baidu-map插件

      $ npm install baudu-map --save

      安装成功之后就可以再页面上显示了,我做的是效果是这样的,一边移动一边获取点的坐标,点击也可以,给大家看看效果图:

       

      最后贴上代码, 

        <template>
          <div>
            <div class="baiduMap">
              <i-form :model="centerStr" :label-width="100">
                <Form-item label="经度">
                  <i-input :value.sync="centerStr.lng"></i-input>
                </Form-item>
                <Form-item label="纬度">
                  <i-input :value.sync="centerStr.lat"></i-input>
                </Form-item>
                <i-button type="primary">提交</i-button>
              </i-form>

              <baidu-map
                class="bm-view"
                ak="你的百度地图ak"
                center="广州市"
                :zoom="12"
                :scroll-wheel-zoom="true"
                @click="getClickInfo"
                @moving="syncCenterAndZoom"
                @moveend="syncCenterAndZoom"
                @zoomend="syncCenterAndZoom">
                  <bm-view style=" 100%; height:500px;"></bm-view>
                  <bm-marker
                    :position="{ lng: centerStr.lng, lat: centerStr.lat }"
                    :dragging="true"
                    animation="BMAP_ANIMATION_BOUNCE">
                  </bm-marker>
                  <bm-control :offset="{ '10px', height: '10px' }">
                    <bm-auto-complete v-model="keyword" :sugStyle="{ zIndex: 999999 }">
                      <input
                        type="text"
                        placeholder="请输入搜索关键字"
                        class="serachinput"/>
                    </bm-auto-complete>
                  </bm-control>
                  <bm-local-search
                   :keyword="keyword"
                   :auto-viewport="true"
                   style="0px;height:0px;overflow: hidden;"
                  ></bm-local-search>
              </baidu-map>
            </div>
          </div>
        </template>
     
        
        <script>
          //地图组件---按需引入
          import {
            BaiduMap,
            BmControl,
            BmView,
            BmAutoComplete,
            BmLocalSearch,
            BmMarker
          } from "vue-baidu-map";
     
          export default {
            components: {
              BaiduMap,
              BmControl,
              BmView,
              BmAutoComplete,
              BmLocalSearch,
              BmMarker
            },
            data: function() {
              return {
                showMapComponent: this.value,
                keyword: "",
                mapStyle: {
                   "100%",
                  height: this.mapHeight + "px"
                },
                centerStr: {
                  lng: "",
                  lat: ""
                }
              };
            },
            watch: {
              value: function(currentValue) {
                this.showMapComponent = currentValue;
                if (currentValue) {
                  this.keyword = "";
                }
              }
            },
            methods: {
              getClickInfo(e) {
              this.centerStr.lng = e.point.lng;
              this.centerStr.lat = e.point.lat;
            },
            syncCenterAndZoom(e) {
              const { lng, lat } = e.target.getCenter();
              this.centerStr.lng = lng;
              this.centerStr.lat = lat;
              this.zoom = e.target.getZoom();
            }
          }
        };
      </script>
     
      <style scoped>
        .head {
          margin-left: 200px;
           100px;
        }
        .baiduMap {
           80%;
          height: 800px;
          margin: 0 auto;
          overflow: hidden;
        }
        .ivu-form-item {
          display: inline-block;
           40%;
        }
        .bm-view > div {
           100%;
          height: 700px !important;
        }
        .serachinput {
           300px;
          box-sizing: border-box;
          padding: 9px;
          border: 1px solid #dddee1;
          line-height: 20px;
          font-size: 16px;
          height: 38px;
          color: #333;
          position: relative;
          border-radius: 4px;
          -webkit-box-shadow: #666 0px 0px 10px;
          -moz-box-shadow: #666 0px 0px 10px;
          box-shadow: #666 0px 0px 10px;
        }
      </style>
      
      写的不足的地方,望大佬指教!

      

  • 相关阅读:
    腾讯TBS加载网页无法自适应记录
    filter过滤器实现验证跳转_返回验证结果
    Oracle不连续的值,如何实现查找上一条、下一条
    springmvc.xml 中 <url-pattern></url-pattern>节点详解
    spring拦截器-过滤器的区别
    (转)spring中的拦截器(HandlerInterceptor+MethodInterceptor)
    @Value("${xxxx}")注解的配置及使用
    mybatis BindingException: Invalid bound statement (not found)
    spring声明式事务管理方式( 基于tx和aop名字空间的xml配置+@Transactional注解)
    Spring事务管理详解_基本原理_事务管理方式
  • 原文地址:https://www.cnblogs.com/0314dxj/p/11139146.html
Copyright © 2020-2023  润新知