怪兽充电小程序

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
第一首先看中心点上有个小图标
实现方式,我们可以使用map 结合一个图片覆盖物实现,在结合定位

   <map id="myMap" 
						show-location
						enable-poi
						enable-building 
						:latitude="latitude"
						:longitude="longitude"
						:markers="markers"
						@regionchange="anchorpointtapmap"
						>
					    <cover-image class="img-map" src="../../static/mark.png" >  </cover-image>
                   </map>


#myMap {
		width: 100%;
		height: 100%;
		position: relative;
	}
	 
.img-map {
			width: 54rpx;
			height:80rpx;
			position: absolute;
			left: calc(50% - 0rpx);
			top: calc(50% - 40rpx);
			transform: translate(-50%,-50%); 
		}
		.coview{
			position: absolute;
			bottom: 0px;
			width: 100%;
			height: 50px;
			background: red;
		}

当我们拖动的时候,点击刷新按钮让中心小图标回来
实现思路,当我们第一获取当前位置的时候,存储一个当前坐标
在移动回来
data中定义两个字段

deflatitude:"",
deflongitude:"",


  <cover-view class="backcenter"  @click="backcenter()">
	<cover-image style="width: 40px; height: 25px;margin: 8px 0px;"   src="../../static/sx.png" ></cover-image >
  </cover-view> 


	backcenter(){
				  this.$nextTick(() => {
					     const mapCtx = wx.createMapContext("myMap",this);
					      mapCtx.moveToLocation({
					          latitude:this.deflatitude,
					          longitude:this.deflongitude,
					          success:() => {
								
							 },
					      });
				  })
			
			},


mounted() {
this.onAuthLocation();
}

    onAuthLocation() {
				      var that =this;
				 	  uni.getLocation({
						  type: 'gcj02',
						  altitude:true,
						  isHighAccuracy:true,
						  success: function (res) {
							  that.latitude =res.latitude;
							  that.longitude =res.longitude;
							  that.deflatitude =res.latitude;
							  that.deflongitude =res.longitude;
						  }
					  });
	         },

充电宝小图标标注只要使用markers
在拖动地图的获取到对应坐标。后台返回当前坐标附近有充电宝的数组,赋值给markers 这里只做死数据演示。
完整代码
在这里插入图片描述
使用uni-app创建项目

pages.json


{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "怪兽充电"
			}
		}
	    ,{
            "path" : "pages/nearshop/nearshop",
            "style" :                                                                                    
            {
                "navigationBarTitleText": "附近门店",
                "enablePullDownRefresh": false
            }
            
        }
        ,{
            "path" : "pages/user/user",
            "style" :                                                                                    
            {
                "navigationBarTitleText": "个人中心",
                "enablePullDownRefresh": false,
				"navigationStyle":"custom",
				"app-plus":{
			     	"titleView":false
				}
            }
            
        }
       
    ],
	"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "怪兽充电",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8"
	}
}



index.vue


<template>
    <view class="page">
	
        <view class="page-body">
                  <map id="myMap" 
						show-location
						enable-poi
						enable-building 
						:latitude="latitude"
						:longitude="longitude"
						:markers="markers"
						@regionchange="anchorpointtapmap"
						>
					    <cover-image class="img-map" src="../../static/mark.png" >  </cover-image>
                   </map>
		
				   <view class="pop-up">
				         <view class="mian">
							 
							  <view class="item1" @click="gonear(1)">
								      <image style="width: 30px; height: 30px; " :mode="aspectFit"
								      src="../../static/md.png"
								       ></image>
								       	 <text>附近门店</text>               
							  </view>
							  <view class="item2">
								   <button type="default" @click="scanCode">扫码充电</button>
							  </view>
							  <view class="item3" @click
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值