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***x5452 分钟前
Java设计模式之策略模式
java·设计模式·策略模式
章鱼哥7305 分钟前
Java 策略模式 + 聚合对象:实现多模块的统计与聚合,快速扩展的实战
java·开发语言·策略模式
h***593333 分钟前
SpringBoot中如何手动开启事务
java·spring boot·spring
倚肆41 分钟前
Java泛型详解:尖括号<>、通配符?与类型参数T
java
韩风66644 分钟前
雪花id改多workerID依赖redis
java
BD_Marathon1 小时前
Eclipse 代码自动补全设置
android·java·eclipse
L.EscaRC1 小时前
深入解析SpringBoot中的循环依赖机制与解决方案
java·spring boot·spring·循环依赖
IT_陈寒1 小时前
Spring Boot 3.2 性能翻倍秘诀:这5个配置优化让你的应用起飞🚀
前端·人工智能·后端
b***67641 小时前
【JavaEE】Spring Web MVC
前端·spring·java-ee
曾经的三心草1 小时前
JavaEE初阶-网络原理1
java·网络·java-ee