您好,欢迎来到刀刀网。
搜索
您的当前位置:首页小程序中使用腾讯地图卫星地图代码示例

小程序中使用腾讯地图卫星地图代码示例

来源:刀刀网

在小程序中使用腾讯地图卫星地图需要以下步骤:

1. 在小程序的 app.json 文件中添加权限配置:

```json
{
  "mp-locations": {
    "scope": "scope.userLocation"
  }
}
```

2. 在对应页面的 wxml 中添加地图组件

```html
<map id="map" 
  latitude="{{latitude}}" 
  longitude="{{longitude}}" 
  scale="{{scale}}" 
  markers="{{markers}}" 
  show-location="{{showLocation}}"
  show-compass="{{showCompass}}"
  enable-overlooking="{{enableOverlooking}}"
  enable-zoom="{{enableZoom}}"
  enable-scroll="{{enableScroll}}"
  style="width: 100%; height: 100%;"></map>
```

3. 在对应页面的 js 文件中引入腾讯地图 SDK 并设置卫星地图:

```javascript
const QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js')

Page({
  data: {
    latitude: 39.984060,
    longitude: 116.307520,
    scale: 15,
    markers: [],
    showLocation: true,
    showCompass: true,
    enableOverlooking: true,
    enableZoom: true,
    enableScroll: true
  },
  onReady: function () {
    const mapCtx = wx.createMapContext('map')
    this.qqmapsdk = new QQMapWX({
      key: '你的腾讯地图 Key'
    })
    this.qqmapsdk.getSatelliteMap({
      success: function (res) {
        mapCtx.setMapStyle({
          style: res.result.style_id
        })
      }
    })
  }
})
```

其中,腾讯地图API Key 可以在腾讯位置服务官网(lbs.qq.com)上申请。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- gamedaodao.com 版权所有 湘ICP备2022005869号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务