在高德地图添加标注物,及点击标注物感应区域重叠问题

本文介绍如何使用高德地图iOS SDK在地图上添加标注物,并解决标注物点击事件误判的问题。通过具体代码示例展示了如何设置标注物的尺寸、位置以及响应点击事件。

高德地图上可以添加覆盖物和标注物(如定位大头针)。
覆盖物MAGroundOverlay会随着地图的放大缩小而等比例的放大缩小,优点页很显然,移动带有大量覆盖物的地图,覆盖物不闪动,很平滑。
标注物MAAnnotationView不会随着地图的放大缩小而改变。缺点是当地图上有大量标注物时,上下左右的移动地图,标注物会有闪动的效果,不平滑(安卓的高德3D地图没有该问题)。若标注物有点击事件,在创建标注物时一定要给它具体的frame,不然会可能看到了标注物大小正常,但是当两个标注物冲动或比较近时,可能误判点击的是那个标注物。这个问题当时难住我三天,后来通过不断试探才找到这个问题的解决方案。具体的代码就是:

annotationView.frame = CGRectMake(0, 0, 32, 42);
            annotationView.image = [UIImage bundleName:@"LChat_RedPacketModule" imageNamed:@"red_business"];
            annotationView.imageView.frame = CGRectMake(0, 0, 32, 42);

具体的完整使用代码:
LCCustomCalloutView.h:

#import <UIKit/UIKit.h>
#import "LCListRedPacketUnitEntity.h"
#import "LCSameCitySearchUnitEntity.h"
@import MAMapKit;

/**分享的图片最大宽度,单位:ps像素(不是物理像素)*/
#define sIconMapImageWidth 32
#define sIconMapImageHeight 42

@interface LCCustomCalloutView : MAAnnotationView


//@property (nonatomic, strong, readwrite) LCCustomCalloutView *calloutView;
@property (nonatomic) CGRect mapFrame;
@property (nonatomic,strong) UIImageView *iconImage;
@property (nonatomic, strong) LCListRedPacketUnitEntity *model;
@property (nonatomic, strong) LCSameCitySearchUnitEntity *sameCitySearchUnitEntity;
@property (nonatomic, copy) void(^selectBlock)(LCListRedPacketUnitEntity *model);
@property (nonatomic, copy) void(^selectSearchBlock)(LCSameCitySearchUnitEntity *sameCitySearchUnitEntity);
@property (nonatomic, strong) MAPointAnnotation *pointAnnotation;
@end

LCCustomCalloutView.m文件:

#import "LCCustomCalloutView.h"
//#import "NSString+Extension.h"


@interface LCCustomCalloutView ()
@property (nonatomic,strong) UILabel *chatelainAddressLabel;
@property (nonatomic,strong) UILabel *incomeDescriptionLabel;
@property (nonatomic,strong) UILabel *incomeLabel;
@property (nonatomic,strong) UILabel *btnTitleLabel;
@property (nonatomic,strong) UIImageView *chatelainAvatarImageView;
@property (nonatomic,strong) UIButton *btn;
//@property (nonatomic,strong) UIImageView *iconImage;
@end

@implementation LCCustomCalloutView
- (instancetype)initWithFrame:(CGRect)frame{
   
   
    
    if (self=[super initWithFrame:frame ]) {
   
   
        
        [self addchildV];
    }
    
    return self;
    
}

- (void)addchildV
{
   
   
    [self iputSubPanel];
}

- (void)iputSubPanel
{
   
   

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
   
   
    BOOL isHaveSingleTap 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值