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

}

});

},

最后显示效果:

相关推荐
小马爱打代码6 分钟前
Spring源码中的设计模式实战:从理论到源码的深度解析
java·spring·设计模式
老码观察8 分钟前
数环通iPaaS架构设计的结构化与模块化方法论——从高内聚低耦合到工程落地的完整指南
java·服务器·网络
Devin~Y18 分钟前
智慧物流+AIGC客服Java大厂面试:Spring Boot、Kafka、Redis、JVM与RAG Agent实战
java·jvm·spring boot·redis·spring cloud·kafka·rag
文心快码BaiduComate19 分钟前
Comate搭载MiniMax M3:支持超长百万上下文
前端·人工智能·后端
浩风祭月19 分钟前
React 18 并发特性实战:用 useTransition 和 useDeferredValue 优化列表搜索体验
前端·react native
WebInfra20 分钟前
TanStack Start 框架正式支持 Rsbuild
前端·javascript·前端框架
Demon1_Coder22 分钟前
智能体的自定义工具
java·linux·前端
老王以为24 分钟前
单仓库下的四十模块 —— React Monorepo 工程架构拆解
前端·react native·react.js
原创小甜甜28 分钟前
OOM 排查复盘:Hutool 序列化 Request 导致 Java Heap Space
java·开发语言·python