最近需求有一个类似共享单车查看附近单车的功能,看了看小程序map api对多点定位显示描述的不怎么清晰。显示定位数组添加多个时就不显示了。踩了几个坑写了几个方法。最终弄出来了。有问题建议欢迎留言。

html:

<map id="map"  scale="{{scale}}" bindcontroltap="controltap" markers="{{markers}}" bindmarkertap="markertap"
latitude="{{latitude}}"
longitude ="{{longitude}}"
controls="{{controls}}" show-location bindregionchange="regionchange" style="width: 100%; height: {{view.Height}}px;"></map>

javascript:

var app = getApp();

Page({
data: {
url:'',
listData: [
{
"id": 1,
"placeName": "中关村广场",
"placeImageUrl": "",
"placeOpenTime": 1505854800,
"placeCloseTime": 1505919600,
"placeAddress": "北京市海淀区中关广场",
"placeLongitude": "116.303900",
"placeLatitude": "39.976460"
}, {
"id": 2,
"placeName": "虎丘的广场",
"placeImageUrl": "",
"placeOpenTime": 1506286800,
"placeCloseTime": 1506258000,
"placeAddress": "江苏省苏州虎丘",
"placeLongitude": "120.410770",
"placeLatitude": "31.325370"
}, {
"id": 3,
"placeName": "东城区广场",
"placeImageUrl": "",
"placeOpenTime": 1506200400,
"placeCloseTime": 1506265200,
"placeAddress": "北京市东城区广场",
"placeLongitude": "116.407526",
"placeLatitude": "39.904030"
}, {
"id": 4,
"placeName": "回龙观广场",
"placeImageUrl": "",
"placeOpenTime": 1506243600,
"placeCloseTime": 1506265200,
"placeAddress": "北京市昌平区回龙观东大街",
"placeLongitude": "116.362300",
"placeLatitude": "40.083480"
}, {
"id": 5,
"placeName": "吴中的广场",
"placeImageUrl": "",
"placeOpenTime": 1506286800,
"placeCloseTime": 1506351600,
"placeAddress": "江苏苏州吴中",
"placeLongitude": "120.416152",
"placeLatitude": "31.322980"
}
],
scale:'15',
Height:'0',
controls:'40',
latitude:'',
longitude:'',
markers: [],
},
onReady: function (e) {
// 使用 wx.createMapContext 获取 map 上下文
this.mapCtx = wx.createMapContext('myMap')
},
onLoad: function () {
var that = this; that.setData({
url: app.globalData.url
}) var data = JSON.stringify({
page: 1,
pageSize: 10,
request: {
placeLongitude: app.globalData.longitude,
placeLatitude: app.globalData.latitude,
userId: app.globalData.userId
}
}) wx.getLocation({
type: 'wgs84', //返回可以用于wx.openLocation的经纬度
success: (res) => {
that.setData({
markers: that.getSchoolMarkers(),
scale: 12,
longitude: res.longitude,
latitude: res.latitude
})
}
}); wx.getSystemInfo({
success: function (res) {
//设置map高度,根据当前设备宽高满屏显示
that.setData({
view: {
Height: res.windowHeight
}, })
}
})
},
controltap(e) {
this.moveToLocation()
},
getSchoolMarkers() { var market = []; for (let item of this.data.listData) { let marker1 = this.createMarker(item); market.push(marker1)
}
return market;
},
moveToLocation: function () {
this.mapCtx.moveToLocation()
},
strSub:function(a){
var str = a.split(".")[1];
str = str.substring(0, str.length - 1)
return a.split(".")[0] + '.' + str;
},
createMarker(point) { let latitude = this.strSub(point.placeLatitude);
let longitude = point.placeLongitude;
let marker = {
iconPath: "../../image/banner5.jpeg",
id: point.id || 0,
name: point.placeName || '',
title: point.placeName || '',
latitude: latitude,
longitude: longitude,
label:{
x:-24,
y:-26,
content: point.placeName
},
width: 30,
height: 30
};
return marker;
}
})

小程序map地图多点定位的更多相关文章

  1. 微信小程序map地图的一些使用注意事项

    1.小程序组件map,在微信7.0.4以上(不包括7.0.4)层级问题官方已作更新,可在map上随意添加任何标签使用z-index即可:微信7.0.4版本以下map组件层级默认是最高的,只能使用官方提 ...

  2. 小程序map地图上显示多个marker

    wxml <map id="myMap" style="width: {{mapWidth}}rpx; height: {{mapHeight}}rpx;" ...

  3. 小程序map地图点击makert放大效果和点击放大地图

    WXML文件和JS文件代码在下方 <view class='map'> <map id="map" longitude="{{location.lng} ...

  4. 微信小程序----map组件实现检索【定位位置】周边的POI

    效果图 实现方法 地图采用微信小程序提供的map组件: 周边的数据坐标点通过高德地图提供的API接口,获取定位位置的周边或者指定位置周边的数据. WXML <view class="m ...

  5. 微信小程序:获取地理定位和显示相应的城市名称。

    最近在看微信小程序,遇到地理定位显示城市名称的问题.本文就是记录这一过程. 解决方案                                                          ...

  6. 支付宝小程序室内地图导航开发-支付宝小程序JS加载esmap地图

    如果是微信小程序开发,请参考微信小程序室内地图导航开发-微信小程序JS加载esmap地图文章 一.在支付宝小程序里显示室内三维地图 需要满足的两个条件 调用ESMap室内地图需要用到小程序web-vi ...

  7. 百度小程序-map组件定位

    给客户开发一个百度小程序,有个地图定位显示.百度小程序内置的api地图是不准的,通过百度一下,查询到坐标偏移算法公式,自己项目中使用,手机测试坐标已经正常显示! 经纬度,通过百度坐标拾取器拾取到! . ...

  8. mpvue小程序开发之 城市定位

    背景: 在进行小程序开发时,有一个定位城市的需求,下面就来讲讲怎么实现这个功能的吧 解决方案: 小程序的wx.getLocation()获得是经纬度并不包含地名,所以要通过经纬度用相应的地图转换出地名 ...

  9. 微信小程序开发demo-地图定位

    要求要完成的功能: 1.要完成的要点是城市定位. 2.就是切换城市. 首页我们先参照微信小程序开放的官方文档找到: 在这里我们可以找到”当前位置经纬度“ getLocation: function ( ...

随机推荐

  1. 百度LBS云搜索时报错 &quot;filter:area is not filteable field, please set property in the cloud-storage

    {"status":2,"message":"filter:area is not filteable field, please set prope ...

  2. [WebGL入门]二十一,从平行光源发出的光

    注:文章译自http://wgld.org/,原作者杉本雅広(doxas),文章中假设有我的额外说明.我会加上[lufy:],另外,鄙人webgl研究还不够深入,一些专业词语.假设翻译有误,欢迎大家指 ...

  3. SpringBoot之Web开发——webjars&静态资源映射规则

    在webjars中找到需要引入的Maven依赖,添加到pom.xml中,即可自动导入相关依赖.

  4. ALSA声卡驱动中的DAPM详解之五:建立widget之间的连接关系

    前面我们主要着重于codec.platform.machine驱动程序中如何使用和建立dapm所需要的widget,route,这些是音频驱动开发人员必须要了解的内容,经过前几章的介绍,我们应该知道如 ...

  5. ZOJ 2397:Tian Ji -- The Horse Racing

    Tian Ji -- The Horse Racing Time Limit: 5 Seconds      Memory Limit: 32768 KB Here is a famous story ...

  6. @注解与普通web.xml的关系

    @WebServlet(name = "SimpleServlet" ,urlPatterns = {"/simple"}) public class Simp ...

  7. YES,IT IS

  8. RDA 字库制作

    制作韩语字库为例: 1.韩语UNICODE 范围 TV_IDF_uni_korean.txt [01fa,] [02c6,02c7] [02c9,02ca] [02cd,02cd] [02d8,02d ...

  9. VPS主机

    腾讯云企业认证 备案域名要是顶级域名格式,所以不能是www.blueheartzf.com,而要是blueheartzf.com

  10. json Date对象在js中的处理办法

    我们在程序用往往通过ajax方式返回json数据,json中包含Date对象时,在js中是Object对象.可以方式获取: 1.new Date(yourJsonDate.time); //你用你的返 ...