微信小程序中怎么实现map地图
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,这篇"微信小程序中怎么实现map地图"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇"微
千家信息网最后更新 2025年11月07日微信小程序中怎么实现map地图
这篇"微信小程序中怎么实现map地图"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇"微信小程序中怎么实现map地图"文章吧。
前言
微信小程序地图操作比较简单,api也很少,使用map组件来展示。说到地图,那就先来看基础定位:
定位用到wx.getLocation(OBJECT)函数,代码如下:
wx.getLocation({ type: 'wgs84', success: function(res) { var latitude = res.latitude var longitude = res.longitude var speed = res.speed var accuracy = res.accuracy }})定位成功会返回四个参数值,如下:
map属性太多,先看一下:
如果用到地图,基本上所有属性都会用到。
下面一一看一下,我们先看效果图吧,先看真相:
这里我只用了一个markers,就是定位当前位置的红色markers,用法如下:
wx.getLocation({ type: 'wgs84', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 success: function (res) { _this.setData({ latitude: res.latitude, longitude: res.longitude, markers: [{ id: "1", latitude: res.latitude, longitude: res.longitude, width: 50, height: 50, iconPath: "/assests/imgs/my.png", title: "哪里" }], circles: [{ latitude: res.latitude, longitude: res.longitude, color: '#FF0000DD', fillColor: '#7cb5ec88', radius: 3000, strokeWidth: 1 }] }) } })这里加了circles,半径是3000米,具体的api可自行看官网。
接下来看看controls,控制层,在地图上显示控件,控件不随着地图移动,看API:
注意看示例图的右上角,有两个按钮,加减号,是控制地图scale的数值变化,动态缩放地图的,controls用法也很简单:
controls: [{ id: 1, iconPath: '/assests/imgs/jian.png', position: { left: 320, top: 100 - 50, width: 20, height: 20 }, clickable: true }, { id: 2, iconPath: '/assests/imgs/jia.png', position: { left: 340, top: 100 - 50, width: 20, height: 20 }, clickable: true } ]最后我们看一张gif图:
最后上一下具体代码:
wxml:
js:
Page({ data: { Height: 0, scale: 13, latitude: "", longitude: "", markers: [], controls: [{ id: 1, iconPath: '/assests/imgs/jian.png', position: { left: 320, top: 100 - 50, width: 20, height: 20 }, clickable: true }, { id: 2, iconPath: '/assests/imgs/jia.png', position: { left: 340, top: 100 - 50, width: 20, height: 20 }, clickable: true } ], circles: [] }, onLoad: function () { var _this = this; wx.getSystemInfo({ success: function (res) { //设置map高度,根据当前设备宽高满屏显示 _this.setData({ view: { Height: res.windowHeight } }) } }) wx.getLocation({ type: 'wgs84', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 success: function (res) { _this.setData({ latitude: res.latitude, longitude: res.longitude, markers: [{ id: "1", latitude: res.latitude, longitude: res.longitude, width: 50, height: 50, iconPath: "/assests/imgs/my.png", title: "哪里" }], circles: [{ latitude: res.latitude, longitude: res.longitude, color: '#FF0000DD', fillColor: '#7cb5ec88', radius: 3000, strokeWidth: 1 }] }) } }) }, regionchange(e) { console.log("regionchange===" + e.type) }, //点击merkers markertap(e) { console.log(e.markerId) wx.showActionSheet({ itemList: ["A"], success: function (res) { console.log(res.tapIndex) }, fail: function (res) { console.log(res.errMsg) } }) }, //点击缩放按钮动态请求数据 controltap(e) { var that = this; console.log("scale===" + this.data.scale) if (e.controlId === 1) { // if (this.data.scale === 13) { that.setData({ scale: --this.data.scale }) // } } else { // if (this.data.scale !== 13) { that.setData({ scale: ++this.data.scale }) // } } },})以上就是关于"微信小程序中怎么实现map地图"这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注行业资讯频道。
地图
内容
程序
坐标
定位
代码
动态
就是
属性
按钮
控件
文章
知识
篇文章
控制
成功
接下来
两个
价值
位置
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
公安机关网络安全管理待遇
星际战争2换服务器
数据库分库分表 2n
网易服务器1.17崩服小技巧
服务器监视终端管理
幻塔经常无法连接服务器
江苏诚信软件开发专业服务
海淀区网络技术服务需求
黑色沙漠没做完季节服务器
MySQL数据库APP图标
聊天服务器源码
源码发到服务器安全吗
阿里巴巴服务器空间要多少
计算机网络技术的试卷
软件开发逻辑导图设计
数据库设计五大阶段
教学管理系统数据库设计论文
中国电信都有哪些服务器
数据库多重插入数据
计算机网络技术+第3版
数据链软件开发回收价
什么是网络安全工程
市公安局网络安全
数据库四级考哪两门
hp服务器自检后开不了机
浙江少儿频道网络安全知识
tmbl数据库
数据库定义的类型数据
数据库 表名命名规范
immediate关闭数据库