微信小程序 地图撒点

news/2024/7/20 4:32:57 标签: 微信小程序, 小程序

1. 小程序>微信小程序 地图撒点

1.1 说明

  首先使用小程序>微信小程序自带标签,并且设置好宽高让地图显示,用longitude和latitude表示中心点。
  (1)show-location 显示带有方向的当前定位点,本项目不需要不添加。
  (2)scale=“4” 缩放比例,缩放级别,取值范围为3-20。
  (3)markers的图标想要圆的可直接让设计做成圆形,用iconPath添加。

1.2. wxml代码

<view class="map-layout">
  <map class="map-contianer" id="myMap" markers="{{markers}}" longitude="{{locObj.longitude}}" latitude="{{locObj.latitude}}" scale='16' show-location="true">
  </map>
</view>

1.3. wxss代码

.map-layout {
  position: relative;
  height: 100vh;
}
.map-contianer{
  width:100%;
  height:100%;
}

1.4. js代码

var app = getApp()
const qqmapsdk = app.globalData.qqmapsdk
Page({

  /**
   * 页面的初始数据
   */
  data: {
 //地图相关
 markers: '', //设置markers属性和地图位置poi,将结果在地图展示
 locObj: {
   latitude: '',
   longitude: '',
   address: ''
 },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
    that.getAddress()
  },
//=======================地图相关===================
getAddress(e) {
  var that = this;
  qqmapsdk.reverseGeocoder({
    success: function (res) {
      that.data.locObj.address = res.result.address
      that.setData({
        locObj: that.data.locObj
      })
      var res = res.result;
      var markerArr = [];
      var curLat=res.location.lat
      var curLng=res.location.lng
      // 36.66645
      // 117.07641
      markerArr.push({ 
        title: res.address,
        id: 0,
        latitude: curLat,
        longitude: curLng,
        iconPath: '/icon_map_addr_hospital.png', 
        width: 28,
        height: 32,
      },{ 
        title: res.address,
        id: 1,
        latitude: (curLat-0.0009),
        longitude:(curLng-0.0007),
        iconPath: '/icon_map_addr_house.png', 
        width: 32,
        height: 32,
      },{ 
        title: res.address,
        id: 2,
        latitude: (curLat+0.0009),
        longitude:(curLng+0.0003),
        iconPath: '/icon_map_addr_wc.png', 
        width: 28,
        height: 32,
      },{ 
        title: res.address,
        id: 3,
        latitude: (curLat-0.0009),
        longitude:(curLng+0.0011),
        iconPath: '/icon_map_addr_wc.png', 
        width: 28,
        height: 32,
      },{ 
        title: res.address,
        id: 4,
        latitude: (curLat+0.0004),
        longitude:(curLng+0.0011),
        iconPath: '/icon_map_addr_house.png', 
        width: 28,
        height: 32,
      },{ 
        title: res.address,
        id: 5,
        latitude: (curLat+0.0004),
        longitude:(curLng-0.0011),
        iconPath: '/icon_map_addr_hospital.png', 
        width: 28,
        height: 32,
      });
      that.data.locObj.latitude = res.location.lat
      that.data.locObj.longitude = res.location.lng
      that.setData({ // 设置markers属性和地图位置poi,将结果在地图展示
        markers: markerArr,
        locObj: that.data.locObj
      });
    },
    fail: function (error) {
      console.error(error);
    },
    complete: function (res) {
      console.log(res);
    }
  })
},
})

1.5. 效果图

在这里插入图片描述


http://www.niftyadmin.cn/n/5231892.html

相关文章

MYSQL8.0 修改字符集和排序规则-企业实战

#MYSQL8.0 修改字符集和排序规则 由于MYSQL8.X 的排序规则从默认5.7的utf8_general_ci 修改为&#xff1a;utf8mb4_0900_ai_ci&#xff0c; 所以不管是MYSQL5.7迁移还是其他的操作导致排序规则更改都需要更改, 要不然会导致表关联join出错. #查询非utf8mb4_0900_ai_ci排序规则…

Unity | 渡鸦避难所-0 | 创建 URP 项目并导入商店资源

0 前言 知识点零零碎碎&#xff0c;没有目标&#xff0c;所以&#xff0c;一起做游戏吧 各位老师如果有什么指点、批评、漫骂、想法、建议、疑惑等&#xff0c;欢迎留言&#xff0c;一起学习 1 创建 3D&#xff08;URP&#xff09;项目 在 Unity Hub 中点击新项目&#xff…

【Android 线程】在子线程中更新UI

线程 2 种基本用法 继承 //定义 class MyThread : Thread() {override fun run() {} } //启动 MyThread.start()接口 //定义 class MyThread : Runnable {override fun run() {} } //启动 var myThread MyThread() Thread(myThread).start()在子线程中更新UI class MainAc…

基于python的FMCW雷达工作原理仿真

这篇文章将介绍如何使用python来实现FMCW工作原理的仿真&#xff0c;第1章内容将介绍距离检测原理&#xff0c;第2章内容会介绍速度检测原理。 第1章 第1部分: 距离检测原理 调制的连续波雷达通常也被叫做调频连续波&#xff08;FMCW&#xff09;雷达是一个使用频率调制来测量…

MQTT分析——CONNECT为例子

源代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net.Sockets;namespace ConsoleApp1 {class Program{static void Main(string[] args){Connect();}/// <summary>/// 向…

CSS新手入门笔记整理:CSS图片样式

图片大小 语法 width:像素值; height:像素值; 图片边框&#xff1a;border 语法 边框&#xff1a;宽度值 样式值 颜色值&#xff1b; border:1px solid red; 图片对齐 水平对齐&#xff1a;text-align 语法 text-align:取值; 属性值 说明 left 左对齐(默认值) cent…

Django回顾【四】之模型层

目录 一、基本使用 1、ORM框架 2、创建表 二、常用和非常用字段 三、常用和非常用字段参数 四、settings配置 五、基本操作 5.1 增加表记录 5.2 删除表纪录 5.3 更新表纪录 5.4 查询表纪录 六、 多表操作-创建关系 七、基于对象的跨表查询 八、基于链表的跨表…

代码随想录第二十一天(一刷C语言)|回溯算法组合

创作目的&#xff1a;为了方便自己后续复习重点&#xff0c;以及养成写博客的习惯。 一、回溯算法 1、种类 排列、组合、分割、子集、棋盘问题 2、回溯步骤 &#xff08;0&#xff09;回溯抽象 回溯法解决的问题均可以抽象为树形结构&#xff08;N叉树&#xff09; &…