微信小程序 地图撒点

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. 效果图

在这里插入图片描述

相关推荐

  1. 程序地图

    2023-12-05 15:30:12       6 阅读
  2. 程序地图案例

    2023-12-05 15:30:12       4 阅读
  3. 程序地图功能详解

    2023-12-05 15:30:12       5 阅读
  4. 程序实现腾讯地图

    2023-12-05 15:30:12       12 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-05 15:30:12       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-05 15:30:12       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-05 15:30:12       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-05 15:30:12       18 阅读

热门阅读

  1. vue3 element-plus el-table表头冻结,表头吸顶

    2023-12-05 15:30:12       40 阅读
  2. 聊聊logback的ThrowableProxyConverter

    2023-12-05 15:30:12       38 阅读
  3. 2022大厂高频面试题之HTML篇

    2023-12-05 15:30:12       43 阅读
  4. Spring-Mybatis读写分离笔记整理

    2023-12-05 15:30:12       26 阅读
  5. PTA 7-238 整数转换为字符串

    2023-12-05 15:30:12       36 阅读
  6. 2023-简单点-tkinter中的ttk和tk

    2023-12-05 15:30:12       41 阅读
  7. RabbitMQ避免重复消费

    2023-12-05 15:30:12       57 阅读
  8. 简谈PostgreSQL的wal_level=logic

    2023-12-05 15:30:12       31 阅读
  9. FlinkSql-Temporal Joins-Lookup Join

    2023-12-05 15:30:12       47 阅读