uniapp地图自定义文字和图标

这是我的结构:

<map class='map' id="map" :latitude="latitude" :longitude="longitude" @markertap="handleMarkerClick" :show-location="true" :markers="covers" />

记住别忘了在data中定义变量:

latitude: '', // 初始纬度

longitude: '', // 初始经度

covers: [], // 覆盖物数组

然后请求位置:

getMyLocation() {

uni.getLocation({

type: 'wgs84',

success: (res) => {

this.jinweidu = res.longitude + ',' + res.latitude

this.latitude = res.latitude

this.longitude = res.longitude

//这是我的请求可以换成你们请求的接口

this.$u.get("/app/store/listNearBy?center=" + this.jinweidu + '&radius=' + 1000).then(

res => {

if (res.code == 200) {

this.listmap = res.data

res.data.forEach(item => { //这是将请求的数据循环并且每个更换图标和文字

const shopCover = {

id: parseFloat(item.storeId),

latitude: item.lat,

longitude: item.lng,

width: 25,

height: 30,

iconPath: 'https://api.ccttiot.com/smartmeter/img/static/uZXgsJE6hXbRSwbKILB4',

label: {

content: item.name,

fontWeight: 700,

color: '#8883F0',

textShadow: '2px 2px 0px white, -2px -2px 0px white, 2px -2px 0px white, -2px 2px 0px white',

style: {

},

}

};

this.covers.push(shopCover) //最后将更改好的数据放到地图数组中

});

}

});

},

fail: (err) => {

console.error('获取位置失败:', err);

}

});

},

最后显示效果:

相关推荐
weixin_307779133 分钟前
Jenkins ASM API 插件:详解与应用指南
java·运维·开发语言·后端·jenkins
天天向上10243 分钟前
Vue 配置一次打包执行多个命令,并将分别输出到不同的文件夹
前端·javascript·vue.js
BD_Marathon8 分钟前
【JavaWeb】HTML——超链接标签
前端·html
彭于晏爱编程13 分钟前
🐻 Zustand 使用指南:从 0 到精通的最快路线
前端
장숙혜14 分钟前
Vue DevTools 速通-掌握开发调试器
前端·javascript·vue.js
ByteX14 分钟前
springboot 项目某个接口响应特别慢排查
java·spring boot·后端
谢尔登17 分钟前
为什么React 17开始无需在组件中引入React了?
前端·react.js·前端框架
ohyeah18 分钟前
JavaScript 面向对象的本质:从对象模板到组合继承的完整演进
前端·javascript
Drift_Dream24 分钟前
虚拟滚动:优化长列表性能的利器
前端
逃离疯人院24 分钟前
前端性能深度解析:网络响应时间与实际渲染时间的鸿沟
前端