微信小程序地图模块
微信小程序的地图模块官方提供的API比较少,详情请见 官方文档
以下为一个示例
<!--pages/location/location.wxml-->
<view class="container">
<view class="page-body"> <view class="page-section page-section-gap">
<map
style="width: 100%; height: 300px;"
markers="{{markers}}"
scale="15"
circles="{{circles}}"
include-points="{{includepoints}}"
>
</map>
</view> <view class='page-section'>
<slider
min='50'
max='500'
value="200"
bindchange="sliderChange"
show-value/>
<view class="textarea-wrp">
{{txtMsg}}
</view>
</view> <view class='page-section'>
<view class='page-body-button'>
<button type="normal" size='mini' bindtap='getLocation'>普通模式</button>
<button type="normal" size='mini' bindtap='tap1'>搜寻模式</button>
</view>
</view> </view>
</view>
/* pages/location/location.wxss */
.wrapper{
height: 100%;
background:#fff;
}
.page-body-form-value{
font-size: 14px;
color:darkturquoise;
font-weight: bold;
padding-left: 15px;
border: 1px solid rgb(72, 165, 131);
border-radius: 4px;
height: 30px;
line-height: 30px;
} .page-body-form-key{
font-size:14px;
padding: 10px;
margin-top:15px;
font-family: "Microsoft Yahei";
font-weight: bold;
height: 30px;
line-height: 30px;
} .page-body-button{
text-align: center;
line-height:;
} button{
margin: 10rpx;
} textarea { padding: 25rpx 0;
}
.textarea-wrp {
padding: 0 25rpx;
background-color: #fff;
}
// pages/location/location.js
var timer1;
Page({
/**
* 页面的初始数据
*/
data: {
location:{},
markers: [{ //标记点
iconPath: "/images/user.png",
id: 0,
latitude: 23.099994,
longitude: 113.324520,
}, {
iconPath: "/images/dog.png",
id: 1,
latitude: 23.099994,
longitude: 113.324520,
}],
circles: [{ //圆
latitude: 23.099994,
longitude: 113.324520,
color: '#FFFFFFAA',
fillColor: '#90EE90AA',
radius: 200
}],
includepoints: [],
}, sliderChange: function (e) {
this.setData({
'circles[0].radius': e.detail.value
})
},
//获取当前位置信息
getLocation: function(e){
var that = this
wx.getLocation({
success: function(res) {
console.log('getLocation success:',res)
that.setData({ //修改markers[0]位置信息(人)
'markers[0].latitude': res.latitude,
'markers[0].longitude': res.longitude,
})
console.log(that.data.markers)
}
})
}, /**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
}, /**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
}, /**
* 生命周期函数--监听页面显示
*/
onShow: function () {
var that = this;
//定时设置人的位置信息
timer1 = setInterval(function () {
wx.getLocation({
success: function (res) {
console.log('获取定位信息成功,', res.latitude, res.longitude);
var points = [{ latitude: res.latitude, longitude: res.longitude },
{ latitude: that.data.markers[1].latitude, longitude: that.data.markers[1].longitude }]
that.setData({
'markers[0].latitude': res.latitude,
'markers[0].longitude': res.longitude,
includepoints: points, //---------包含点 看location.wxml
'circles[0].latitude': res.latitude,
'circles[0].longitude': res.longitude,
})
console.log(that.data.markers)
},
fail: function () {
console.log('获取定位信息失败');
}
})
}, 5000);
}, /**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
clearInterval(timer1);
}, /**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
微信小程序地图模块的更多相关文章
- Odoo 开源微信小程序商城模块
详见:http://oejia.net/blog/2018/09/13/oejia_weshop_about.html oejia_weshop Odoo 微信小程序商城模块 oejia_weshop ...
- 微信小程序--地图上添加图片
如何在微信小程序地图添加上,添加图片? 在微信小程序中,地图的层级最高,所以我们没有办法,通过定位,在地图上添加图片等信息; 处理办法: 添加控件:controls; 其中有个属性position,进 ...
- 微信小程序地图开发总结
最近在做一个微信小程序地图插件,通过传入起始位置名称和经纬度信息,就可以跳转到路线规划插件页面中,在该页面中,可以根据起始位置查询自驾,公共交通,步行等方式的路线信息,并且在地图上显示路线信息,在这个 ...
- 微信小程序地图总结
小程序官方的 map地图说明文档已经非常详细了,但是鉴于如果没有一个合适的使用场景,对于刚接触 map 的初级开发,看着这些繁杂又贼多的属性名和字段,外加急切的开发需求,晕头转向是不可避免的了.接下来 ...
- 微信小程序地图控件篇 ---自定义图标被地图覆盖的问题
今天在做微信小程序的时候遇到这个这样的问题 需要在地图上加个一个自定义的图标控件 类似这样的 刚开始的时候怎图片一直会被地图组件覆盖 ,要怎么解决这个问题 我去翻了下小程序的文档 有个cover ...
- 微信小程序--地图组件与api-模拟器上返回的scale 与真机上不同--bindregionchange触发图标一直闪现问题
场景:根据地理定位获取不同地区的充电桩位置,要求 1.平移的时候,跟随坐标变化展示不同区域的坐标点信息 2.不同的缩放等级,14以下,展示聚合点数据,14以上,展示真正的站点信息: 3.点击聚合点的时 ...
- 微信小程序 地图地址解析
1.微信小程序提供了几个方式,引入地图, wx.getLocation(OBJECT) 获取当前的地理位置.速度.当用户离开小程序后,此接口无法调用:当用户点击“显示在聊天顶部”时,此接口可继续调用 ...
- 百度地图坐标偏移,微信小程序地图偏移问题,腾讯地图坐标偏移
解决方案: 如果用百度的地图获取的坐标点,在微信小程序内使用,就会出现偏移 算法(lat和lng是经纬度,球面坐标): To_B是转到百度,To_G是转到GCJ-02(谷歌,高德,腾讯) var TO ...
- 微信小程序蓝牙模块
蓝牙部分知识 关于Service: 每个设备包含有多个Service,每个Service对应一个uuid 关于Characteristic 每个Service包含多个Characteristic,每个 ...
随机推荐
- 安装mysql-5.6版本步骤与卸载
官网下载完解压后: 1.环境变量配置Path D:\mysql-5.6.40-winx64\bin(你的mySql5.6的路径到bin)2.找到D:\mysql-5.6.40-winx64文件中的 ...
- 【题解】Willem, Chtholly and Seniorious Codeforces 896C ODT
Prelude ODT这个东西真是太好用了,以后写暴力骗分可以用,写在这里mark一下. 题目链接:ヽ(✿゚▽゚)ノ Solution 先把原题解贴在这里:(ノ*・ω・)ノ 简单地说,因为数据是全部随 ...
- K8S Api Server认证
目录 认证类型 基于CA证书的双向认证 apiserver端配置 生成客户端私钥和证书 master核心组件与apiserver的认证方式 HTTP Token认证 HTTP Basic认证 kube ...
- gitlab的备份与恢复与迁移
一.gitlab的备份1.1 创建备份目录,并授权 1 2 3 4 [root@linux-node1 ~]# mkdir /data/backups/gitlab -p [root@linux-no ...
- jQuery中使用attribute,prop获取,设置input的checked值
1.prop方法获取.设置checked属性 当input控件checkbox设置了checked属性时,无论checked=”“或 checked=”checked”,$(obj).prop(“ch ...
- 新建 Vue项目 使用iView报错解决
错误如下: error in ./src/index.less Module build failed: // https://github.com/ant-design/ant-motion/iss ...
- Java并发编程原理与实战二十八:信号量Semaphore
1.Semaphore简介 Semaphore,是JDK1.5的java.util.concurrent并发包中提供的一个并发工具类. 所谓Semaphore即 信号量 的意思. 这个叫法并不能很好地 ...
- 基本控件文档-UITextField属性
CHENYILONG Blog 基本控件文档-UITextField属性 Fullscreen UITextField属性技术博客http://www.cnblogs.com/ChenYilong ...
- C++利用cin输入时检测回车的方法
今天做TJU的OJ ,其中一道题是先读入一个字符串,再读入一个整数,循环往复,直到字符串是空,也就是说回车键结束循环. 但是cin对空格和回车都不敏感,都不影响继续读入数据,所以需要一种新的方式检测回 ...
- HDU 6096 String (AC自动机)
题目链接 Problem Description Bob has a dictionary with N words in it. Now there is a list of words in wh ...