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

}

});

},

最后显示效果:

相关推荐
带刺的坐椅几秒前
AspectJ、Spring AOP 与 Solon AOP:Java AOP 框架的三剑客
java·spring·solon·aop·aspectj
q***64971 分钟前
SpringSecurity踢出指定用户
android·前端·后端
Coding_Doggy4 分钟前
链盾shieldchiain | 团队功能、邀请成员、权限修改、移除成员、SpringSecurity、RBAC权限控制
java·开发语言·数据库
q***76664 分钟前
SpringSecurity 实现token 认证
android·前端·后端
llxxyy卢5 分钟前
xss-maps(1-12)尝试思路过关加源码分析
前端·xss
Seven975 分钟前
剑指offer-41、和为S的连续正数序列
java
小璞9 分钟前
一、React Fiber 架构与任务调度详解
前端·react.js·前端框架
小璞9 分钟前
四、虚拟 DOM 与 Diff 算法:架构设计的智慧
前端·react.js·前端框架
南蓝10 分钟前
【AI 日记】调用大模型的时候如何按照 sse 格式输出
前端·人工智能
一树论12 分钟前
浏览器插件开发经验分享二:如何处理日期控件
前端·javascript