高德地图上可以添加覆盖物和标注物(如定位大头针)。
覆盖物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

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

被折叠的 条评论
为什么被折叠?



