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

最后显示效果:

相关推荐

  1. Uniapp导航栏右侧定义图标文字按钮

    2024-06-15 06:40:06       7 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-15 06:40:06       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-15 06:40:06       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-15 06:40:06       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-15 06:40:06       18 阅读

热门阅读

  1. 【代码】3d->video

    2024-06-15 06:40:06       8 阅读
  2. 前端常用排序算法

    2024-06-15 06:40:06       5 阅读
  3. 鸿蒙Arkts上传图片并获取接口返回信息

    2024-06-15 06:40:06       9 阅读
  4. .NETCORE 微软企业登录

    2024-06-15 06:40:06       6 阅读
  5. bash和sh区别

    2024-06-15 06:40:06       6 阅读
  6. 从零手写实现 nginx-23-directive IF 条件判断指令

    2024-06-15 06:40:06       7 阅读
  7. svm 超参数

    2024-06-15 06:40:06       6 阅读
  8. shell判断语句练习

    2024-06-15 06:40:06       6 阅读
  9. MySQL周内训参照2、DDL与DML语句

    2024-06-15 06:40:06       9 阅读