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);

}

});

},

最后显示效果:

相关推荐
陈随易17 分钟前
RollCode:不只是在做页面,而是在缩短“从需求到上线”的整条链路
前端·后端
mygljx24 分钟前
spring-ai 下载不了依赖spring-ai-openai-spring-boot-starter
java·人工智能·spring
jaysee-sjc32 分钟前
【练习十二】Java实现年会红包雨小游戏
java·开发语言·算法·游戏·intellij-idea
炽烈小老头41 分钟前
【每天学习一点算法 2026/03/17】括号生成
前端·学习·typescript
indexsunny44 分钟前
互联网大厂Java求职面试实战:核心技术与业务场景解析
java·spring boot·redis·微服务·kafka·互联网大厂·面试技巧
大漠_w3cpluscom1 小时前
如何在 CSS 中正确使用 if()
前端
eason_fan1 小时前
踩坑记录:Mac M系列芯片下 pnpm dlx 触发的 esbuild 架构不匹配错误
前端·前端工程化
小涛不学习1 小时前
Java 后端核心框架面试题(Spring / SpringMVC / MyBatis / MyBatis-Plus)
java·spring·mybatis
程序猿大波1 小时前
基于java,SpringBoot和Vue餐饮公司食堂管理系统设计
java·vue.js·spring boot
似水明俊德1 小时前
01-C#.Net-泛型-学习笔记
java·笔记·学习·c#·.net