小程序腾讯地图绘制大头针,以及还原位置

在这里插入图片描述上一篇是绘制路线,这一篇是绘制大头针获取经纬度,以及左下角还原本地位置

代码片

wxml文件
在这里插入图片描述
**

js文件

**

var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');

// 实例化API核心类
var demo= new QQMapWX({
  key: '你的key' // 必填
});

Page({
data: {
controls:[],
province: ‘’,//省
city: ‘’,//市
district: ‘’,//区
}

    //经纬度转换为地址:
  getLocal: function (latitude, longitude) {
    let vm = this;
      console.log("经纬度转换为地址:")
    demo.reverseGeocoder({
      location: {
        latitude: latitude,
        longitude: longitude
      },
      success: function (res) {
        console.log("打印1")
        console.log(JSON.stringify(res));
       
        let province = res.result.ad_info.province
        let city = res.result.ad_info.city
        let district = res.result.ad_info.district
        console.log("目前省市区为:" + province + ":" + city + ":" + district)
        console.log(res.result.location.lat)
        console.log(res.result.location.lng)
        vm.setData({
          province: province,//省
          city: city,//市
          district: district,//区

        })

      },
        //失败回调
      fail: function (res) {
        console.log(res);
      },
        //完成回调
      complete: function (res) {
        // console.log(res);
      }
    });
  },

bindregionchange: function (e) {
    var that = this
    if (e.type == "begin") {
      console.log("begin");
    } else if (e.type == "end") {
      var mapCtx = wx.createMapContext("map")
      mapCtx.getCenterLocation({
        success: function (res) {
          console.log(res)
          var latitude = res.latitude
          var longitude = res.longitude
          that.getLocal(latitude, longitude)
        }
      })
    }
  },

//  控件的点击事件
  bindcontroltap: function (e) {
    switch (e.controlId) {
      case 1:
      console.log("触发了大头针")
      // 当点击图标location.png的图标,则触发事件movetoPositioon()
      break;
      case 2:
        console.log("触发了定位")
        this.movetoPosition();
        break;

    }
  },
  //移动定点
  movetoPosition: function () {
    var mapCtx = wx.createMapContext("map")
    mapCtx.moveToLocation();
  },
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值