山东大学项目实训——地图圈系统——微信小程序(2)

一、申请开发者密钥key(用的是腾讯地图)

1.打开腾讯位置服务:https://lbs.qq.com/

2.打开微信小程序JavaScripSDK
在这里插入图片描述
3.点击申请密钥,注册新账号
在这里插入图片描述

4.注册完成后在自己邮箱验证,然后添加key
在这里插入图片描述
5.添加完成后就得到了自己的key在这里插入图片描述

二、下载微信小程序JavaScriptSDK

在这里插入图片描述

三、安全域名设置

在小程序管理后台 -> 开发 -> 开发管理 -> 开发设置 -> “服务器域名” 中设置request合法域名,添加https://apis.map.qq.com

四、map组件基础属性

属性类型默认值必填说明
longitudenumber中心经度
latitudenumber中心纬度
scalenumber16缩放级别,取值范围为3-20
min-scalenumber3最小缩放级别
max-scalenumber20最大缩放级别
markersArray. 标记点
coversArray.即将移除,请使用 markers
polylineArray. 路线
circlesArray.
controlsArray.控件(即将废弃,建议使用 cover-view 代替)
include-pointsArray.缩放视野以包含所有给定的坐标点
show-location booleanfalse显示带有方向的当前定位点
polygons Array. 多边形
subkey string个性化地图使用的key
layer-stylenumber1个性化地图配置的 style,不支持动态修改
rotatenumber0旋转角度,范围 0 ~ 360, 地图正北和设备 y 轴角度的夹角
skewnumber0倾斜角度,范围 0 ~ 40 , 关于 z 轴的倾角
enable-3Dbooleanfalse展示3D楼块(工具暂不支持)
show-compassbooleanfalse显示指南针
show-scalebooleanfalse显示比例尺,工具暂不支持
enable-overlookingbooleanfalse开启俯视
enable-zoombooleantrue是否支持缩放
enable-scrollbooleantrue是否支持拖动
enable-rotatebooleanfalse是否支持旋转
enable-satellitebooleanfalse是否开启卫星图
enable-trafficbooleanfalse是否开启实时路况
enable-poiboolean是否展示 POI 点
enable-buildingboolean是否展示建筑物
settingobject配置项
bindtapeventhandle点击地图时触发,2.9.0起返回经纬度信息
bindmarkertapeventhandle点击标记点时触发,e.detail = {markerId}
bindlabeltapeventhandle点击label时触发,e.detail = {markerId}
bindcontroltapeventhandle点击控件时触发,e.detail = {controlId}
bindcallouttapeventhandle点击标记点对应的气泡时触发e.detail = {markerId}
bindupdatedeventhandle在地图渲染更新完成时触发
bindregionchangeeventhandle视野发生变化时触发
bindpoitapeventhandle点击地图poi点时触发,e.detail = {name, longitude, latitude}
bindanchorpointtapeventhandle点击定位标时触发,e.detail = {longitude, latitude}

五、map组件应用

微信小程序用map组件来进行地图的显示,新建一个页面名为regeo。
1.regeo.wxml文件代码:

<view class="map_container">

  <map class="map" id="mymap" longitude="{{longitude}}" latitude="{{latitude}}" include-points="{{points}}" markers='{{markers}}' controls="{{controls}}" enable-traffic="{{isRealTraffic}}" enable-satellite="{{showweixing}}" bindcontroltap="clickcontrol"
    bindmarkertap="clickmarkers" bindtap="onTapMap" bindpoitap="onTapPoi">
  </map>
</view>

2.regeo.js文件代码:
js是页面逻辑文件,想要获取自己目前的位置,要使用wx.getLocation方法,在页面的onload方法中编写。

  onLoad() {
    // 实例化API核心类
    qqmapsdk = new QQMapWX({
      key: 'LE2BZ-ZIPKU-AWCVW-4EGZV-YAMY2-36BS4'
    });
    var _this = this
    wx.getLocation({
      success: function(res) {
        _this.setData({
          longitude:res.longitude,
          latitude: res.latitude,
          markers: [{
            id: 0,
            longitude: res.longitude,
            latitude: res.latitude,
            iconPath: '../../src/images/ding.png',
            width: 32,
            height: 32
          }]
        })
      
      },
    })
    

  }

3.regeo.wxss文件代码:

.map_container{
  position: absolute;
  top:  0;
  bottom: 0;
  left: 0;
  right: 0;
}
.map{
  width: 100%;
  height: 100%;
}

4.在微信小程序底部增加按钮:
app.json代码:

"window": {
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "地图圈",
    "navigationBarTextStyle": "black"
  },
  "tabBar": {
    "list": [
      {
        "pagePath": "pages/regeo/regeo",
        "text": "地图",
        "iconPath": "src/images/map1.png",
        "selectedIconPath": "src/images/map.png"
      },
      {
        "pagePath": "pages/navigation/navigation",
        "text": "导航",
        "iconPath": "src/images/dh.png",
        "selectedIconPath": "src/images/dh1.png"
      },
      {
        "pagePath": "pages/my/my",
        "text": "我的",
        "iconPath": "src/images/my.png",
        "selectedIconPath": "src/images/my1.png"
      }
    ]
  },
  "permission": {
    "scope.userLocation": {
      "desc": "你的位置信息将用于小程序定位"
    }
  },

5.效果展示:
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值