微信小程序 - 多地点标识(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 ...
随机推荐
- 获取mac地址和IP地址方式
第一种 public class OperateMAC{ public static string GetMacByWMI() { string MacAddr = null; //Managemen ...
- 我们应选择怎样的IT公司
最近经常有朋友提问,同时收到几家公司的offer,应该如何选择,或者找工作的时候,找怎样的公司,我在这里阐述一下我的观点.但愿对朋友们有所帮助. 还是那句老话,选择什么样的公司,关键是你想要过什么样的 ...
- Submile text3 安装使用技巧
第一次用submile text3,发现还是有一些东西需要配置的,而且submile text3是最近发布的,和原来的submile text2还是有一些区别的.这两天自己配置了一下,用起来感觉还是不 ...
- ThreadLocal深度解析
本文基于jdk1.8.0_66写成 0. ThreadLocal简介 ThreadLocal可以提供线程内的局部对象,合理的使用可以避免线程冲突的问题比方说SimpleDateFormat是线程不安全 ...
- php 单文件上传
php 单文件上传 通过 PHP,可以把文件上传到服务器. 创建一个文件上传表单 允许用户从表单上传文件是非常有用的. 请看下面这个供上传文件的 HTML 表单: Filename: 请留意如下有关此 ...
- 配置虚拟主机 和 打war包
配置一台虚拟主机? 在[tomcat]/conf/server.xml文件中的<Engine>标签内部添加一个<Host>标签: <H ...
- 安装Team Services Agent Win7
现状:项目现时使用的是Team Services,使用Team Services可以控制其中的一台Build Server,从Github提取代码,并在Build Server进入编译打包处理(son ...
- 山东省第七届省赛 D题:Swiss-system tournament(归并排序)
Description A Swiss-system tournament is a tournament which uses a non-elimination format. The first ...
- 基于tinkphp3.2获取openid
<?php namespace Home\Controller; use Think\Controller; /** * 基础 */ class BaseController extends C ...
- 洛谷——P1480 A/B Problem
P1480 A/B Problem 题目描述 输入两个整数a,b,输出它们的商(a<=10^5000,b<=10^9) 输入输出格式 输入格式: 两行,第一行是被除数,第二行是除数. 输出 ...