在小程序开发的过程中,我碰到过一个做map的需求,在我开发的时候我碰到了一些问题,这里总结出来,给大家一些解决方法。

简易小程序dome下载

代码片段分享:

js部分:

var amapFile = require('../../libs/amap-wx.js');//如:..­/..­/libs/amap-wx.js
Page({
data: {
markers: [],
latitude: '',
longitude: '',
textData: {},
dome:false
},
onLoad: function() {
var that = this; wx.getLocation({
type: 'wgs84',
success: (res) => {
console.log(res);
that.setData({
latitude: res.latitude,
longitude: res.longitude
})
var marker = [{
id: 1,
latitude: res.latitude,
longitude: res.longitude,
iconPath: "../../images/marker.png",
width: 22,
height: 32,
callout: {
content: "你的位置\n换行内容",
color: "#333333",
fontSize: 13,
borderRadius: 20,
bgColor: "#ffffff",
textAlign: "center" ,
padding: 10,
display: 'ALWAYS'
}
}]
that.setData({
markers: marker
});
that.setData({
dome: true
});
},
}); },
})

  

页面部分

<view class="map_container">
<map class="map" id="map" longitude="{{longitude}}" latitude="{{latitude}}" scale="11" markers="{{markers}}" wx:if="{{dome}}"></map>
</view>

  

css部分

.map_container{
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width:750rpx;
height: 100vh;
}
map{
width:100%;
height: 100%;
}

  

遇到的问题:看上面的代码,大家可以发现,我的map是用if来控制的,这样是为了防止markers动态更新后map没反应,这里我的解决方法是直接重构,如果有其他大家欢迎大家在下面分享出来。

最新文章

  1. Microsoft 家族新成员 Datazen 移动BI 介绍
  2. Openstack之Swift架构(Cloud Storage)
  3. 最近写的页面,含有大量的ajax
  4. hibernate Restrictions用法
  5. Spring-----9、容器中bean的生命周期
  6. centos6.4下没有heartbeat包解决办法
  7. 关于GROUP BY的应用
  8. ABP入门系列(14)——应用BootstrapTable表格插件
  9. 非等高cell实战(01)-- 实现微博页面
  10. 【原创】Python第二章——行与缩进
  11. Java爬虫之下载全世界国家的国旗图片
  12. network is unreachable 网关PING不通解决办法
  13. vue教程自学笔记(二)
  14. Authorization With Pundit
  15. python取余
  16. Linux 下载安装配置Redis完整步骤
  17. P2399 non hates math
  18. npm WARN unmet dependency错误解决方法
  19. Deep learnin简介
  20. 润乾配置连接kingbase(金仓)数据库

热门文章

  1. 大白话详解大数据hive知识点,老刘真的很用心(3)
  2. python爬虫之解析链接
  3. 顶会两篇论文连发,华为云医疗AI低调中崭露头角
  4. CentOS7 实战源码部署php服务与nginx 的整合
  5. Arduino IDE 开发ESP-01/ESP8266-01读取DHT11温度湿度传感器
  6. maven中pom的结构介绍
  7. 事件驱动之JDK观察者模式
  8. reactor模式:多线程的reactor模式
  9. Node.js gulp安装与使用出现问题与解决
  10. windows10系统修改JDK版本后配置环境变量不生效怎么办