ios – 使用GMUClusterManager的自定义标记

ios – 使用GMUClusterManager的自定义标记,第1张

概述我想使用GMUClusterManager显示自定义标记.我按照标记聚类 here的所有步骤进行 *** 作. 但是有这样的蓝色和红色图标. 但是,当我放大该地图时,它只显示红色标记,但我不希望这样. 有实例方法,我已经实现了我的逻辑,但没有用. - (instancetype)initWithMapView:(GMSMapView *)mapView clusterIconGenerator:(id<G 我想使用GMUClusterManager显示自定义标记.我按照标记聚类 here的所有步骤进行 *** 作.

但是有这样的蓝色和红色图标.

但是,当我放大该地图时,它只显示红色标记,但我不希望这样.

有实例方法,我已经实现了我的逻辑,但没有用.

- (instancetype)initWithMapVIEw:(GMSMapVIEw *)mapVIEw clusterIconGenerator:(ID<GMUClusterIconGenerator>)iconGenerator{    if ((self = [super init])) {        GMSMarker *marker= [GMSMarker markerWithposition:CLLocationCoordinate2DMake(24.0,75.30)];        UIVIEw *customMarker =[[UIVIEw alloc] initWithFrame:CGRectMake(0,63,40)];        customMarker.backgroundcolor = [UIcolor bluecolor];        marker.iconVIEw = [self EmployeeMarker:0] ;        marker.appearanimation = kGMSMarkerAnimationPop;        marker.map = mapVIEw;    }    return self;}-(UIVIEw *)EmployeeMarker:(int)labelTextInt{    UIVIEw *customMarker =[[UIVIEw alloc] initWithFrame:CGRectMake(0,40)];    UIImageVIEw *imgVIEwCustomMarker = [[UIImageVIEw alloc]initWithFrame:CGRectMake(0,15,24,25)];    imgVIEwCustomMarker.image = [UIImage imagenamed:@"iconMapUser.png"];    [customMarker addSubvIEw:imgVIEwCustomMarker];    UIVIEw *vIEwratingCustom = [[UIVIEw alloc] initWithFrame:CGRectMake(15,40,15)];    vIEwratingCustom.backgroundcolor = [UIcolor colorWithRed:192.0/255.0 green:192.0/255.0 blue:192.0/255.0 Alpha:1.0];    UILabel *lblratingEmployees = [[UILabel alloc] initWithFrame:CGRectMake(8,1,17,8)];    lblratingEmployees.textcolor = [UIcolor colorWithRed:0.00/255.0 green:100.0/255.0 blue:150.0/255.0 Alpha:1.0];    lblratingEmployees.text = @"1";    lblratingEmployees.Font = [UIFont FontWithname:@"Helvetica-Bold" size:10];    [lblratingEmployees sizetoFit];    [vIEwratingCustom addSubvIEw:lblratingEmployees];    UIImageVIEw *imageVIEwStar = [[UIImageVIEw alloc] initWithFrame:CGRectMake(25,3,10,8)];    imageVIEwStar.image = [UIImage imagenamed:@"iconBlueStar.png"];    [vIEwratingCustom addSubvIEw:imageVIEwStar];    [customMarker addSubvIEw:vIEwratingCustom];    return customMarker;}

我已经使用这种方法显示默认为红色的标记数量.

ID<GMUClusteralgorithm> algorithm = [[GMUNonHIErarchicaldistanceBasedAlgorithm alloc] init];ID<GMUClusterIconGenerator> iconGenerator = [[GMUDefaultClusterIconGenerator alloc] init];ID<GMUClusterRenderer> renderer =  [[GMUDefaultClusterRenderer alloc] initWithMapVIEw:_mapVIEw                                clusterIconGenerator:iconGenerator];_clusterManager =  [[GMUClusterManager alloc] initWithMap:_mapVIEw algorithm:algorithm renderer:renderer]; // Generate and add random items to the cluster manager.// [self generateClusterItems];for (int i = 0; i<latitudeArray.count; i++) {    ID<GMUClusterItem> item =    [[POIItem alloc]initWithposition:CLLocationCoordinate2DMake([[latitudeArray objectAtIndex:i]doubleValue],[[longitudeArray objectAtIndex:i]doubleValue]) name:@"name"];    [_clusterManager addItem:item];}

Adde代表和集群方法.

[_clusterManager cluster]; [_clusterManager setDelegate:self mapDelegate:self];

所以请帮我添加自定义标记来代替默认的红色.

解决方法 您需要创建符合GMUClusterIconGenerator协议的自定义类:

CustomClusterIconGenerator.h文件

@interface CustomClusterIconGenerator : NSObject<GMUClusterIconGenerator>@end

CustomClusterIconGenerator.m文件

@implementation CustomClusterIconGenerator- (UIImage *)iconForSize:(NSUInteger)size {    // Return custom icon for cluster    return [UIImage imagenamed:@"Your Custom Cluster Image"];}- (UIImage *)iconForMarker {    // Return custom icon for pin    return [UIImage imagenamed:@"Your Custom Marker Image"];}- (CGPoint)markerIconGroundAnchor {    // If your marker icon center shifted,return custom value for anchor    return CGPointMake(0,0);}- (CGPoint)clusterIconGroundAnchor {    // If your cluster icon center shifted,0);}@end

然后,而不是

ID<GMUClusterIconGenerator> iconGenerator = [[GMUDefaultClusterIconGenerator alloc] init];

使用

CustomClusterIconGenerator *iconGenerator = [[GMUDefaultClusterIconGenerator alloc] init];

这是我的项目的例子:

总结

以上是内存溢出为你收集整理的ios – 使用GMUClusterManager的自定义标记全部内容,希望文章能够帮你解决ios – 使用GMUClusterManager的自定义标记所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1105443.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存