自己记录一下uniapp开发小程序关于map地图问题
<map style="width:750rpx; height:100vh;" scale="17" show-location="true" :latitude="latitude"
:longitude="longitude" :markers="markers"></map>
1 . 自定义图标不显示
data() {
return {
title: 'map',
longitude:'122.106863',
latitude:'30.016028',
//longitude:'',
//latitude:'',
markers:[],
}
},
经纬度要先给一个值,如果一开始是空,那么markers不会显示,后面再通过把准确的经纬度赋值就可以, 这个具体什么原因我也不清楚,有知道的欢迎,评论区指点一下。
- 自定义图片在模拟器上可以显示,但是在真机调试或者上线体验版不显示问题
引入的自定义图片路径必须是绝对路径(/static),不能是相对路径(…/static)
onLoad(options) {
this.longitude = options.longitude;
this.latitude = options.latitude;
},
onShow() {
this.markers= [{
id: 0, //id 必填项
width: 50,
height: 50,
longitude: this.longitude,
latitude: this.latitude,
iconPath: '/static/images/location1.png', //重点在路径这里
}];
},
ps: 1. 我的longitude,latitude 是上一个页面传入;
2. markers赋值可以在onLoad,也可以在onShow。