微信小程序 - 多地点标识(map)
演示如下:


wxml
<map id="map" scale="{{scale}}" controls="{{controls}}" bindcontroltap="controltap" markers="{{markers}}" bindmarkertap="markertap" bindregionchange="regionchange" show-location style="width: 100%; height: 580px;"></map>
js
let hospitalData = require('hospitalData')
Page({
data: {
centerX: 0.0,
centerY: 0.0,
//可能我标识的地点和你所在区域比较远,缩放比例建议5;
scale:15,
markers: [],
controls: [{
id: 1,
iconPath: '/image/location-control.png',
position: {
left: 0,
top: 10,
width: 40,
height: 40
},
clickable: true
}]
},
onReady: function(e) {
// 使用 wx.createMapContext 获取 map 上下文
this.mapCtx = wx.createMapContext('myMap')
},
onLoad: function() {
console.log('地图定位!')
let that = this
wx.getLocation({
type: 'gcj02', //返回可以用于wx.openLocation的经纬度
success: (res) => {
let latitude = res.latitude;
let longitude = res.longitude;
let marker = this.createMarker(res);
this.setData({
centerX: longitude,
centerY: latitude,
markers: this.getHospitalMarkers()
})
}
});
},
/**
* 标示点移动触发
*/
regionchange(e) {
console.log(e.type)
},
/**
* 点击标识点触发
*/
markertap(e) {
console.log(e)
},
/**
* control控件点击时间
*/
controltap(e) {
console.log(e.controlId)
this.moveToLocation()
},
/**
* 获取医院标识
*/
getHospitalMarkers() {
let markers = [];
for (let item of hospitalData) {
let marker = this.createMarker(item);
markers.push(marker)
}
return markers;
},
/**
* 移动到自己位置
*/
moveToLocation: function() {
let mpCtx = wx.createMapContext("map");
mpCtx.moveToLocation();
},
/**
* 还有地图标识,可以在name上面动手
*/
createMarker(point) {
let latitude = point.latitude;
let longitude = point.longitude;
let marker = {
iconPath: "/image/location.png",
id: point.id || 0,
name: point.name || '',
latitude: latitude,
longitude: longitude,
width: 25,
height: 48
};
return marker;
}
})
hospitalData.js (模拟数据)
module.exports = [{
"id": 1,
"name": "永州市中心医院",
"longitude": "111.62852107566833",
"latitude": "26.42142999357519"
},
{
"id": 2,
"name": "永州市中医院",
"longitude": "111.5972679762268",
"latitude": "26.44470581245983"
}
]
运行示例时,建议放在同一目录下.
微信小程序 - 多地点标识(map)的更多相关文章
- 微信小程序 - 回到自己位置(map)
演示效果: 图片资源 index.js /** * 回到自己位置,在cover-image上绑定点击事件即可. */ clickcontrol(e) { let mpCtx = wx.createMa ...
- uni-app使用wx-canvas实现微信小程序上显示地图map和坐标geo
源码 <template> <view class="echart-box"> <canvas class="ec-canvas" ...
- 微信小程序--获取用户地理位置名称(无须用户授权)的方法
准备 1.在http://lbs.qq.com/网站申请key 2.在微信小程序后台把apis.map.qq.com添加进request合法域名 效果 添加封装 /** * 发起网络请求 * @par ...
- 微信小程序开发——后端Java(一)
一.前言 最近接触了小程序的开发,后端选择Java,因为小程序的代码运行在腾讯的服务器上,而我们自己编写的Java代码运行在我们自己部署的服务器上,所以一开始不是很明白小程序如何与后台进行通信的,然后 ...
- 微信小程序自动定位,通过百度地图根据经纬度获取该地点所在城市信息
微信小程序获得经纬度 var that = this wx.getLocation({ type: 'wgs84', success(res) { console.log(res) that.setD ...
- 微信小程序----map组件实现检索【定位位置】周边的POI
效果图 实现方法 地图采用微信小程序提供的map组件: 周边的数据坐标点通过高德地图提供的API接口,获取定位位置的周边或者指定位置周边的数据. WXML <view class="m ...
- 微信小程序map组件z-index的层级问题
说起微信小程序的map组件,可以说是良心之作了,一个组件解决了所以接入地图的所有麻烦,但是在实际小程序的试用过程中还是存在点问题的.如下情景:刚开始接入map组件的时候是在微信开发工具的模拟器上预览的 ...
- Fundebug微信小程序BUG监控服务支持Source Map
摘要: 自动还原真实出错位置,快速修复BUG. Source Map功能 微信小程序的Source Map功能目前只在 iOS 6.7.2 及以上版本支持. 微信小程序在打包时,会将所有 js 代码打 ...
- 微信小程序_(map)简单的小地图
map地图效果 官方文档:传送门 Page({ data: { markers: [{ iconPath: "/resources/others.png", id: 0, lati ...
随机推荐
- 手机端iscoll插件的使用方法
除了以前版本的iScroll的特性以外,iScroll 4还包括如下的特性: (1)缩放(Pinch/Zoom) (2)拉动刷新(Pull up/down to refresh) (3)速度和性能提升 ...
- java中Math.abs(-2147483648)的返回值应该是什么?
我觉得这是一个非常有意思的问题,Math.abs(-2147483648)的返回值应该是什么? java计算结果 为什么没有得到正数结果呢? 首先我们先看下java区分整数正负的原理.在二进制的情况下 ...
- Ajax 生成流文件下载(实现代码)
// 绑定导出按钮 $("#btnExport").clickCheckLogin(function () { var form = $("<form> ...
- c#读取LOG文件并解决读取提示被其他进程占用问题
c# 读写文件时文件正由另一进程使用,因此该进程无法访问该文件,在IO处理上遇到了无法操作的问题. 文件“C:\u_ex.log”正由另一进程使用,因此该进程无法访问该文件. u_ex.log是一个日 ...
- EA(Enterprise Architect) UML 建模之活动图
一.活动图的概念作用 活动图本质上是一种流程图,它描述活动的序列,即系统从一个活动到另一个活动的控制流. 活动图的作用:描述用例 . 描述类的操作.描述算法(单独使用) 二. 活动图的基本符号 ...
- 将win平台上的mysql数据复制到linux上报错Can't write; duplicate key in table
将win平台上的mysql数据复制到linux上报错Can't write; duplicate key in table xxx 新年新气象,果然在新年的第一天就遇到了一个大坑,项目在win上跑的没 ...
- 分分钟搞定 JSP 技术
一.JSP的语法 1.模版元素 写在JSP中的html内容 在翻译后的Servlet中, 直接被out.write原样输出 2.JSP脚本表达式 格式: ...
- web api 返回数据
一.Webapi的接口返回值类型 主要有四种类型 :void,HttpResponseMessage,IHttpActionResult,其他 1. void [HttpGet] public voi ...
- struts 2.5 访问未定义 action 时报错的问题
转载请注明: 仰望高端玩家的小清新 使用 struts 的时候我们自己设计的action毕竟是有限的,那么我们就需要使用一种方法来限制用户输入未定义的action. 网上很多解决方案都是一个抄一个,没 ...
- [Atcoder Grand Contest 003] Tutorial
Link: AGC003 传送门 A: 判断如果一个方向有,其相反方向有没有即可 #include <bits/stdc++.h> using namespace std; ]; map& ...