uni-app map组件使用聚合时ios的markertap事件返回值为0

uni-app map组件使用聚合时ios的markertap事件返回值为0

开发环境 版本号 项目创建方式
Windows 21H1 HBuilderX

操作步骤:

<template>  
    <div class="map_box">  
        <map class="map_box" id='myMap' :scale='center.scale' :longitude='center.longitude'  @markertap='markertap'   :latitude='center.latitude'>  

        </map>  
    </div>  
</template>  

<script>  
    export default {  
        onReady() {  

            this.mapContext = uni.createMapContext("myMap", this)  
            this.mapContext.initMarkerCluster({  
                    enableDefaultStyle: false,  
                    zoomOnClick: true,  
                    gridSize: 60,  
                    complete(res) {  
                    }  
                  });  

                  this.mapContext.on("markerClusterCreate", (e) => {  
                  });  
                  this.mapContext.on('markerClusterClick', (res) => {  
                  })  
                  this.mapContext.addMarkers({   
                    markers:[{id:1,longitude:114.308743,latitude:30.589295,joinCluster: true, }],  
                    clear: true,  
                    complete(res) {  
                        console.log(1111111111111)  
                    }  
                    })  
        },  
        data() {  
            return {  
                title: 'Hello',  
                center:{  
                    scale:10,  
                    longitude:114.308743,  
                    latitude:30.589295  
                },  
            }  
        },  
        onLoad() {  

        },  
        methods: {  
            markertap(e){  
                console.log(e)  
            }  
        }  
    }  
</script>  

预期结果:

  • markertap的返回事件 markerId=1

实际结果:

  • markertap的返回事件 markerId=0


更多关于uni-app map组件使用聚合时ios的markertap事件返回值为0的实战教程也可以访问 https://www.itying.com/category-93-b0.html

6 回复

已确认在iOS上有问题

更多关于uni-app map组件使用聚合时ios的markertap事件返回值为0的实战教程也可以访问 https://www.itying.com/category-93-b0.html


什么时候搞定一下。。。。

HX 3.3.2+ 版本已修复此问题

使用 3.3.2 Alpha getLocation使用高德、或者系统都返回如下: 不支持某个提供者,如:不支持腾讯地图 { “errMsg”: “getLocation:fail Not Support Provider,https://ask.dcloud.net.cn/article/282”, “errCode”: -1503, “code”: -1503 }

回复 b***@163.com: 在单独发个帖子反馈一下吧

这是一个已知的iOS平台特定问题。当使用地图聚合功能时,iOS设备上的markertap事件返回的markerId始终为0,而Android设备能正常返回正确的markerId。

问题原因: iOS原生地图SDK在聚合模式下,点击事件返回的是聚合簇的信息,而非原始标记点的信息,导致无法获取正确的markerId。

解决方案:

  1. 使用markerClusterClick事件替代(推荐):

    this.mapContext.on('markerClusterClick', (res) => {
        console.log('聚合点击事件:', res)
        // res中包含聚合簇的信息和包含的marker列表
    })
    
  2. 通过聚合簇信息获取marker列表

    this.mapContext.on('markerClusterClick', (res) => {
        const clusterId = res.clusterId
        // 可以通过clusterId获取该聚合簇包含的所有marker
        // 需要自行维护marker与聚合簇的映射关系
    })
回到顶部