vue 制作的腾讯地图、QQ地图坐标采集器 pc端 手机端

  • 前言
    -1、腾讯地图官方有相关案例,使用很简单,框架引入和链接跳转两个方式,具体参考官方文档:
    https://lbs.qq.com/tool/component-picker.html
    但是这个案例每次打开都需要设备定位,很慢,而且很多时候打开失败。严重影响我项目的流畅性。
    -2、因此参考官方案例自己写了一个。
    -3、用到vue,vant框架,jq(只用到他的跨域jsonp数据请求),vant,jq用到的东西很少,为了加载更快更快,有兴趣的可以原生js写请求。
  • 一、效果
    在这里插入图片描述
  • 二、key申请
    参考以下文章:
    https://blog.csdn.net/chenwen112/article/details/102910337
  • 三、html框架
<body>
    <div v-cloak="" id="app">
        <van-cell class="search">
            <van-search v-model="pickObj.poiaddress" @input="searchKeyword" @focus="showsuggestion" :show-action="showcancel" placeholder="搜索地点" @cancel="onCancel" />
        </van-cell>
        <div id="container" class="containerOuter">
            <div class="marker">
                <i></i>
                <img :class="{bounceInDown:hasclass}" width="26px" height="36px" src="https://3gimg.qq.com/lightmap/components/locationPicker2/image/marker.png" />
            </div>
            <!-- 返回当前位置 -->
            <div class="go-back-pos">
                <i></i>
            </div>

            <div id="map-info">
                <!-- 比例尺 -->
                <div class="scale">200</div>
                <div class="qqmap-text-logo"></div>
            </div>

            <div class="to-right">
                <!-- 缩放按钮 -->
                <a class="cbutton" id="btn-zoom">
                    <i id="btn-zoom-in" class="icon-zoom-in" data-adtag="zoomin">+</i>
                    <i id="btn-zoom-out" class="icon-zoom-out" data-adtag="zoomout">-</i>
                </a>
            </div>
        </div>
        <div v-if="suggestionshow" class="suggestion-wrap">
            <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="searchKeyword">
                <van-cell class="cell_li" clickable v-for="(item,key) in suggestionlist.data" :key="key" @click="pantolocation(key,1)">
                    <div class="poi-title">{{item.title}}</div>
                    <div class="poi-address">{{item.address}}</div>
                </van-cell>
            </van-list>
        </div>
        <div id="info" class="info">
            <van-list v-model="loading2" :finished="finished2" finished-text="没有更多了" @load="searchKeyword">
                <van-cell class="info_li" clickable v-for="(item,key) in nearbylist.data" :key="key" @click="pantolocation(key,2)">
                    <div class="info-title">{{item.title}}</div>
                    <div class="info-address">{{item.address}}</div>
                    <i class="active" v-if="getabs([item.location.lat,item.location.lng,pickObj.latlng.lat,pickObj.latlng.lng])" style="display: inline-block;"></i>
                </van-cell>
            </van-list>
        </div>

    </div>
</body>
  • 四、css部分
        [v-cloak] {
            display: none
        }
        
        html {
            font-size: calc(100vw/10)
        }
        
        * ::-webkit-scrollbar {
            display: none;
        }
        
        .__web-inspector-hide-shortcut__ {
            display: none!important;
        }
        
        #app {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
            box-sizing: border-box;
        }
        
        .search {
            padding: 0;
        }
        
        #container {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 45%;
            overflow: hidden;
            box-sizing: border-box;
            border-bottom: 1px solid #d3d3d3;
            border-top: 1px solid #d3d3d3;
        }
        
        #info {
            margin: 0;
            padding: 0;
            width: 100%;
            height: calc(55% - 54px);
            overflow-y: scroll;
            box-sizing: border-box;
        }
        
        #container .marker {
            position: relative;
            top: 50%;
            left: 50%;
            width: 26px;
            height: 36px;
            margin-top: -28px;
            margin-left: -12px;
            z-index: 6
        }
        
        #container .marker img {
            z-index: 1;
            position: absolute
        }
        
        #container .marker i {
            width: 8px;
            height: 8px;
            background: url(https://3gimg.qq.com/lightmap/components/locationPicker2/image/plus.png) no-repeat;
            background-size: 100% 100%;
            position: absolute;
            bottom: -4px;
            left: 50%;
            margin-left: -4.5px;
            z-index: 0;
            display: none
        }
        
        #container .go-back-pos {
            width: 44px;
            height: 44px;
            position: absolute;
            left: 7px;
            bottom: 7px;
            z-index: 6;
            background: url(https://3gimg.qq.com/lightmap/components/locationPicker2/image/navbg.png) no-repeat top left;
            background-size: 44px 44px
        }
        
        #container .go-back-pos i {
            background: url(https://3gimg.qq.com/lightmap/components/locationPicker2/image/nav.png) no-repeat center center;
            background-size: 24px 24px;
            display: block;
            width: 44px;
            height: 44px
        }
        
        #container #map-info {
            position: absolute;
            left: 58px;
            bottom: 10px;
            z-index: 6;
            width: 46px
        }
        
        #container #map-info .scale {
            font-size: 10px;
            text-align: center;
            position: relative;
            line-height: 1;
            white-space: nowrap;
            padding-bottom: 3px;
            margin-bottom: 21px;
            left: 2px
        }
        
        #container #map-info .scale:before {
            left: -1px;
            right: -1px;
            bottom: -3px;
            border: 3px #fff solid
        }
        
        #container #map-info .scale:after {
            left: 0;
            right: 0;
            bottom: -2px;
            border: 1px #000 solid
        }
        
        #container #map-info .scale:after,
        #container #map-info .scale:before {
            content: '';
            display: block;
            position: absolute;
            height: 3px;
            border-top: 0
        }
        
        #container #map-info .qqmap-text-logo {
            width: 64px;
            height: 16px;
            background: url(https://3gimg.qq.com/lightmap/components/locationPicker2/image/logo.png) no-repeat left top;
            background-size: 64px 16px;
            position: absolute;
            left: 0;
            bottom: 0;
            z-index: 6
        }
        
        #container #map-info .scale {
            text-shadow: #fff 0 -1px, #fff 1px 0, #fff 0 1px, #fff -1px 0
        }
        
        #container .to-right {
            position: absolute;
            bottom: 10px;
            right: 10px;
            z-index: 10;
            width: 40px;
            height: 80px;
            background: #fff;
            border: 1px solid #bababa;
            border-radius: 50px;
            box-shadow: 0 0 6px rgba(0, 0, 0, .1);
            text-align: center;
            font-size: 30px;
            display: none
        }
        
        #container .to-right i {
            width: 100%;
            height: 40px;
            line-height: 40px;
            display: block
        }
        
        .suggestion-wrap {
            position: absolute;
            top: 54px;
            bottom: 0;
            z-index: 7;
            width: 100%;
            height: calc(100% - 56px);
            overflow-y: scroll;
            background: #ffffff;
            z-index: 99;
        }
        
        .suggestion-wrap ::-webkit-scrollbar {
            display: none;
        }
        
        .suggestion-wrap .suggestion-scroller {
            width: 100%
        }
        
        .suggestion-wrap .cell_li {
            position: relative;
            display: block;
            padding-top: 8px;
            padding-left: 60px;
            border: none;
            background: url(https://3gimg.qq.com/lightmap/components/locationPicker2/image/search.png) no-repeat 30px 13px;
            background-size: 16px 16px;
            margin-left: -15px;
            height: 58px;
            overflow: hidden
        }
        
        .suggestion-wrap .poi-title {
            font-size: 14px;
            line-height: 27px;
            color: #333;
            font-weight: 400;
            display: block;
            width: 100%;
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden
        }
        
        .suggestion-wrap .poi-address {
            font-size: 12px;
            color: gray;
            height: 20px;
            line-height: 20px;
            margin: 0;
            width: 100%;
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden;
            display: block
        }
        
        #info .info_li {
            position: relative;
            display: block;
            padding-top: 8px;
            border: none;
            height: 58px;
            overflow: hidden;
        }
        
        #info .info_li .active {
            width: 16px;
            height: 16px;
            display: none;
            background: url(https://3gimg.qq.com/lightmap/components/locationPicker2/image/currentPos.png) no-repeat right center;
            background-size: 16px 16px;
            position: absolute;
            right: 15px;
            top: 50%;
            margin-top: -8px
        }
        
        #info .info-title {
            font-size: 14px;
            line-height: 27px;
            color: #333;
            font-weight: 400;
            display: block;
            width: 100%;
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden
        }
        
        #info .info-address {
            font-size: 12px;
            color: gray;
            height: 20px;
            line-height: 20px;
            margin: 0;
            width: 100%;
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden;
            display: block;
        }
        
        .bounceInDown {
            animation: bounceInDown 500ms infinite;
            animation-direction: alternate;
            -webkit-animation: bounceInDown 500ms infinite;
            -webkit-animation-direction: alternate
        }
        
        .csssprite {
            display: none!important;
        }
        
        @-webkit-keyframes bounceInDown {
            0%,
            60%,
            75%,
            90%,
            to {
                -webkit-transition-timing-function: cubic-bezier(.215, .61, .355, 1);
                transition-timing-function: cubic-bezier(.215, .61, .355, 1)
            }
            0%,
            to {
                -webkit-transform: translate3d(0, 0, 0);
                transform: translate3d(0, 0, 0)
            }
            25% {
                -webkit-transform: translate3d(0, -30px, 0);
                transform: translate3d(0, -10px, 0)
            }
            50% {
                -webkit-transform: translate3d(0, -15px, 0);
                transform: translate3d(0, -20px, 0)
            }
            75% {
                -webkit-transform: translate3d(0, -4px, 0);
                transform: translate3d(0, -10px, 0)
            }
        }
        
        @keyframes bounceInDown {
            0%,
            60%,
            75%,
            90%,
            to {
                -webkit-transition-timing-function: cubic-bezier(.215, .61, .355, 1);
                transition-timing-function: cubic-bezier(.215, .61, .355, 1)
            }
            0%,
            to {
                -webkit-transform: translate3d(0, 0, 0);
                transform: translate3d(0, 0, 0)
            }
            25% {
                -webkit-transform: translate3d(0, -30px, 0);
                transform: translate3d(0, -10px, 0)
            }
            50% {
                -webkit-transform: translate3d(0, -15px, 0);
                transform: translate3d(0, -20px, 0)
            }
            75% {
                -webkit-transform: translate3d(0, -4px, 0);
                transform: translate3d(0, -10px, 0)
            }
        }
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值