• 微信小程序-腾讯地图


    index.wxml

    <view>
      <map id="map" longitude="{{ longitude }}" latitude="{{ latitude }}" markers="{{ markers }}" bindtap="maptap" bindregionchange="regionChange" bindmarkertap="markertap" show-location style="100vw; height: 90vh;"></map>
    </view>

    index.js

    //index.js
    //获取应用实例
    const app = getApp();
    //引入SDK核心类
    var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
    //实例化API核心类
    var qqmapsdk = new QQMapWX({
      key: 'GMQBZ-BNVCX-REY4S-ZXZZS-42NUJ-CQF6F'
    });
    
    Page({
      data: {
        adrValue: '',
        longitude: 120.19663,
        latitude: 35.95995,
        markers: []
      },
      onReady(e) {
        var mapCtx = wx.createMapContext('map');
      },
      onLoad () {
        var _this = this;
        wx.getLocation({
          type: 'gcj02', //返回可以用于wx.openLocation的经纬度
          success: function (res) {
            var longitude = res.longitude;
            var latitude = res.latitude;
            _this.setData({
              longitude: longitude,
              latitude: latitude
            });
            _this.setMarkers(_this, longitude, latitude);
          }
        })
      },
      //获取input搜索值
      getAdressValue(e) {
        this.data.adrValue = e.detail;
      },
      //搜索按钮点击事件-搜索地址
      searchAdr(e) {
        var _this = this;
        var val = this.data.adrValue;
        if(val==''){
          wx.showToast({
            title: '地址不能为空',
            icon: 'none',
            duration: 1500
          });
        }else{
          qqmapsdk.geocoder({
            address: val,
            success(res){
              var longitude = res.result.location.lng;
              var latitude = res.result.location.lat;
              _this.setData({
                longitude: longitude,
                latitude: latitude
              });
            },
            fail(error) {
              wx.showToast({
                title: '未搜索到你想看的区域',
                icon: 'none',
                duration: 1500
              });
            }
          });
        }
      },
      //拖拽地图事件-标记点跟随地图中心点移动
      regionChange(res) {
        var _this = this;
        var mapCtx = wx.createMapContext('map');
        if(res.type==='end'){
          mapCtx.getCenterLocation({
            success(response) {
              _this.setMarkers(_this, response.longitude, response.latitude);
            }
          });
        }
      },
      //点击地图事件-添加点击位置标记并把点击位置作为中心点
      maptap() {
        var _this = this;
      },
      //点击标记点事件-
      markertap(e) {
        console.log(e.markerId);
      },
      //设置marker以及中心点位置
      setMarkers(_this, long, lat) {
        //获取附近10个最近的酒店位置
        // app.request({
        //   url: 'test.php',
        //   data: {
        //     longitude: long,
        //     latitude: lat,
        //   },
        //   success(res) {
    
        //   }
        // });
        var point = [
          { id: 1, longitude: 120.20663, latitude: 35.95995, name: '青岛西海岸新区武夷山路店', address: '青岛市西海岸新区武夷山路165号' },
          { id: 2, longitude: 120.18553, latitude: 35.96975, name: '青岛西海岸新区武夷山路店', address: '青岛市西海岸新区武夷山路165号' },
          { id: 3, longitude: 120.18553, latitude: 35.94175, name: '青岛西海岸新区武夷山路店', address: '青岛市西海岸新区武夷山路165号' }
        ];
        point.splice(0, 0, { id: 0, longitude: long, latitude: lat });
        var mark = [];
        for (var key in point) {
          if (key === '0') {
            mark.push({
              iconPath: 'images/mark.png',
              id: point[key].id,
              longitude: point[key].longitude,
              latitude: point[key].latitude,
               30,
              height: 38
            });
          } else {
            mark.push({
              iconPath: 'images/marker-bg.png',
              id: point[key].id,
              longitude: point[key].longitude,
              latitude: point[key].latitude,
               21,
              height: 25,
              callout: {
                content: point[key].name + '
    ' + point[key].address, //换行用'
    '
                fontSize: 14,
                bgColor: '#fff',
                borderWidth: 1,
                borderColor: '#ccc',
                display: 'BYCLICK', //ALWAYS:始终显示,BYCLICK:点击显示
                padding: 5
              }
            });
          }
          _this.setData({
            markers: mark
          });
        }
      }
    })
  • 相关阅读:
    java 在线网络考试系统源码 springboot mybaits vue.js 前后分离跨域
    springboot 整合flowable 项目源码 mybiats vue.js 前后分离 跨域
    flowable Springboot vue.js 前后分离 跨域 有代码生成器 工作流
    Flowable 工作流 Springboot vue.js 前后分离 跨域 有代码生成器
    java 企业 网站源码 后台 springmvc SSM 前台 静态化 代码生成器
    java 进销存 商户管理 系统 管理 库存管理 销售报表springmvc SSM项目
    基于FPGA的电子计算器设计(中)
    基于FPGA的电子计算器设计(上)
    FPGA零基础学习:SPI 协议驱动设计
    Signal tap 逻辑分析仪使用教程
  • 原文地址:https://www.cnblogs.com/shirliey/p/12124103.html
Copyright © 2020-2023  润新知