iOS - 集成高德SDK解决Marker点重复点击无效问题
场景:
在处理Marker点击事件时,此时地图上有Marker点A及Marker点B,当选中Marker点A后,SDK方法
"didSelectAnnotationView"响应了点击事件,并进行了对应的逻辑处理(我在此进行了弹窗操作).
当关闭弹窗想再次选中Marker点A,此时"didSelectAnnotationView"不再响应.需选中Maker点B
后方法才会再次响应.也就是说当连续选中同一个Marker点时会导致"didSelectAnnotationView"
出现不响应的情况.
方案一: ///如果已经是选中状态,再次点击不会触发此回调。取消选中需调用
-(void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view{
[mapView deselectAnnotation:view.annotation animated:YES];
}
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
// [self.aOverlays addObject:annotation];
if ([annotation isKindOfClass:[MAUserLocation class]]) {
NSLog(@"用户定位点");
if (self.startCoordinate.latitude == ) {
// [self requestData:((MAUserLocation *)annotation).location.coordinate filed:@"priority"];
self.startCoordinate = ((MAUserLocation *)annotation).location.coordinate;
self.filed = @"";//priority
[self loadData];
}
self.startCoordinate = ((MAUserLocation *)annotation).location.coordinate; return nil;
}
if ([annotation isKindOfClass:[MAPointAnnotation class]])
{
static NSString *customReuseIndetifier = @"customReuseIndetifier"; SDCustomAnnotationView *annotationView = (SDCustomAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:customReuseIndetifier]; if (annotationView == nil)
{
annotationView = [[SDCustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:customReuseIndetifier]; }
kWeakSelf(self);
annotationView.secletAnnotation = ^{
NSInteger row = [weakself.annotations indexOfObject:annotation];
NSLog(@"点击了---->%ld",(long)row);
};
annotationView.canShowCallout = YES;
annotationView.image = nil; if ([annotation isKindOfClass:[MANaviAnnotation class]])
{
switch (((MANaviAnnotation*)annotation).type)
{
// case MANaviAnnotationTypeRailway:
// poiAnnotationView.image = [UIImage imageNamed:@"railway_station"];
// break;
//
// case MANaviAnnotationTypeBus:
// poiAnnotationView.image = [UIImage imageNamed:@"bus"];
// break;
//
// case MANaviAnnotationTypeDrive:
// poiAnnotationView.image = [UIImage imageNamed:@"car"];
// break;
//
case MANaviAnnotationTypeWalking:
[self.aOverlays addObject:annotation];
annotationView.image = [UIImage imageNamed:@"man_map"];
break;
// case MANaviAnnotationTypeRiding:
// poiAnnotationView.image = [UIImage imageNamed:@"ride"];
// break;
//
default:
break;
}
}
else
{ annotationView.image = [UIImage imageNamed:@"addr_map"];
annotationView.count = annotation.subtitle;
} return annotationView; }
return nil;
}
方案二:
针对上述问题,可在创建Annotationview时给这个Annotationview添加Tap手势
自己对事件进行处理不依赖SDK提供的方法
/**
* @brief 根据anntation生成对应的View(设置标准样式)
* @param mapView 地图View
* @param annotation 指定的标注
* @return 生成的标注View
*/
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation
{
if ([annotation isKindOfClass:[MAPointAnnotation class]])
{
static NSString *pointDefaultIndentifier = @"pointDefaultIndentifier";
AnnotationViewManager *annotationView = (AnnotationViewManager *)[mapView dequeueReusableAnnotationViewWithIdentifier:pointDefaultIndentifier];
if (annotationView == nil)
{
annotationView = [[AnnotationViewManager alloc] initWithAnnotation:annotation reuseIdentifier:pointDefaultIndentifier];
// 给Marker点添加手势
[annotationView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onMarkerClick:)]];
}
annotationView.centerOffset = CGPointMake(, -);
annotationView.image = [UIImage imageNamed:@"map_tubiao_zuche_icon"];
return annotationView;
}
return nil;
}
// Marker选中事件
- (void)onMarkerClick:(UITapGestureRecognizer *)gesture
{
// 这里做你想的事情
MAAnnotationView *annoView = (MAAnnotationView*)gesture.view;
NSLog(@"选中了: %@",annoView.annotation.title); // 解决5.0.0上Annotation选中后重用的bug.
if(annoView.annotation == self.mapView.selectedAnnotations.firstObject)
{
if(annoView.selected == NO)
{
[annoView setSelected:YES animated:YES];
}
return;
}
else
{
[self.mapView selectAnnotation:annoView.annotation animated:YES];
}
}
iOS - 集成高德SDK解决Marker点重复点击无效问题的更多相关文章
- iOS - (集成支付宝SDK大坑总结)
其实集成支付宝相对于集成微信支付来说,支付宝算是简单的了,后续有空再去研究微信支付,现目前先总结一下集成支付宝所遇到的坑,其实支付宝的坑也不算太多,细算下来大概5-6个左右,但是其报错方式有点恶心,不 ...
- iOS通用链接(Universal Links)突然点击无效的解决方案
接上文<微信中通过页面(H5)直接打开本地app的解决方案>已经把iOS搞定并且已经正常能跑了,突然就再也用不了了... 问题描述 测试告诉我,如果从微信打开App之后,点击App右上角的 ...
- 解决jquery zclip 插件点击无效的问题
使用jquery zclip 用于页面复制文本内容. 首先引入js <script type="text/javascript" src="../js/jquery ...
- iOS 集成百度地图 位置偏移问题
iOS 集成百度SDK 请参考 百度地图官方文档 ,这里不就多啰嗦了 本文介绍的是在百度地图上根据经纬度,自定义气泡时,气泡位置的偏移,在我们天朝这种事是很常见的,也见怪不怪了,在项目中使用的百度地图 ...
- 李洪强iOS之集成极光推送三iOS集成指南
李洪强iOS之集成极光推送三iOS集成指南 SDK说明 适用版本 本文匹配的 SDK版本:r2.1.5 以后.查看最近更新了解最新的SDK更新情况.使用Xcode 6及以上版本可以使用新版Push S ...
- iOS之防止用户重复点击Button(按钮)问题
在项目中,我们往往会遇到这样的问题:因为网络较慢的原因,用户会不耐烦的一直去点击按钮,这样导致的结果时:相关代码一遍一遍的被重复执行,如果按钮的事件是网络请求的话,这样又导致一种网络请求的循环.所以我 ...
- 手把手教你搞定个推iOS推送SDK集成
以下是一位开发者在集成个推iOS推送SDK过程中的真实经历. 作者:Ezreallp 一次偶然的机会,公司的项目要用到推送,我自己本来就很懒,不愿意去弄整套APNS的流程,刚好之前跟朋友聊起过他们的产 ...
- iOS小技巧:用runtime 解决UIButton 重复点击问题
http://www.cocoachina.com/ios/20150911/13260.html 作者:uxyheaven 授权本站转载. 什么是这个问题 我们的按钮是点击一次响应一次, 即使频繁的 ...
- Android集成高德地图如何自定义marker
高德地图自定义Marker 高德地图默认的marker样式是这种 一般的修改样式是通过icon接口来调整 MarkerOptions markerOptions = new MarkerOptions ...
随机推荐
- 转 asp.net mvc 身份验证中返回绝对路径的ReturnUrl
原文:http://www.cnblogs.com/hyl8218/archive/2011/11/22/2259116.html 从HttpUnauthorizedResult的源码可以看出,Htt ...
- FIlter(2)—案例
案例 demo2,login.jsp请求提交到hello.jsp,该页面中有两个text,分别使用两个Filter链拦截,验证账号密码是否正确,把账号密码设置到Filter初始化参数中 login.j ...
- mybatis foreach中collection的三种用法
原文:https://www.cnblogs.com/xiemingjun/p/9800999.html foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach ...
- SpringCloud无废话入门02:Ribbon负载均衡
1.白话负载均衡 在上一篇的介绍中,我们创建了两个一模一样的服务提供者:Provider1和Provider2,然后它们提供的服务也一模一样,都叫Hello-Service.为什么一样的服务我们要部署 ...
- DBS:TestSystem
ylbtech-DBS:TestSystem A, 返回顶部 2. -- ================================= -- 类别表 -- ================= ...
- CentOS7本地安装MySQL5.7
操作系统:3.10.0-514.el7.x86_64 安装包:mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz 1:检查是否安装了 libaio(centos7默认 ...
- PHP异步扩展Swoole笔记(1)
安装Swoole扩展 通过pecl安装, 系统中最好已经有http2依赖, 如果是Ubuntu, 可以直接通过apt安装nghttp2, 如果是Centos或者需要自己编译, 在Github下载ngh ...
- C# Cache缓存读取设置
先创建一个CacheHelper.cs类,代码如下: using System; using System.Web; using System.Collections; using System.We ...
- Jenkins自动部署增加http状态码校验
公司推进Jenkins自动化部署,因为web站点都是集群部署,部署需要测试指定服务器web服务是否成功启动,页面是否正常访问,经过不断baidu发现,python的request模块可以很好的解决这一 ...
- mysql触发器详解 mysql触发器
目录 21.1. CREATE TRIGGER语法 21.2. DROP TRIGGER语法 21.3. 使用触发程序 MySQL 5.1包含对触发程序的支持.触发程序是与表有关的命名数据库对象,当表 ...