IOS 高德地图 标注无法选中的一种情况

贴一段代码

if (!_bCenter) {
        [self.aMapView setCenterCoordinate:marker.coordinate];
        _bCenter = YES;
}
if (bshow) {
        [self.aMapView selectAnnotation:marker animated:YES];
}

在执行添加annotation之后立刻执行了上述代码,先设置了地图中心位置,然后选中该annotation,结果annotation经常未被选中,我研究了一下高德地图annotationView的加载机制,发现在地图刚移入时才加载之前添加的annotation,此时立刻设置选中该annotation会出现不响应的情况。所以改了下代码写法,问题解决,代码如下:

if (!_bCenter) {
        [self.aMapView setCenterCoordinate:marker.coordinate];
        _bCenter = YES;
}
    
/**
    延时100毫秒 设置选中当前annotation 由于高德地图annotation加载机制的问题,
    在地图刚移入时才加载之前添加的annotation,此时立刻设置选中该annotation会
    出现不响应的情况(高德地图BUG)此处采用GCD延时方式执行选中annotation
    操作。
*/
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(100 * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
   if (bshow) {
         [self.aMapView selectAnnotation:marker animated:YES];
    }
});
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容