gpt4 book ai didi

ios - MKMapView 中的所有 Annotation 对用户不可见

转载 作者:可可西里 更新时间:2023-11-01 04:43:10 29 4
gpt4 key购买 nike

我正在使用 MKMapView 并在 map 上添加了一些注释图钉。所有注释都属于不同的国家/地区,因此我无法将所有注释都设置为对用户可见。

请尝试使用以下纬度和经度进行注释。

第一个注释纬度:23.029690

第一个注释经度: 72.527359

第二个注释纬度:34.210855

第二个注释经度: -118.622636

向 map View 添加注释的代码。

CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([[dicObjects valueForKey:K_Latitude] doubleValue], [[dicObjects valueForKey:K_Longitude] doubleValue]);
MyCustomAnnotation *myCustomAnnotation = [[MyCustomAnnotation alloc]initWithTitle:[NSString stringWithFormat:@"%@ ",[dicObjects valueForKey:K_Title]] Subtitle:[NSString stringWithFormat:@"%@",[dicObjects valueForKey:K_SubTitle]] andDescritpion:[NSString stringWithFormat:@"%@",[dicObjects valueForKey:K_TitelDes]] withLocation:coordinate andImageName:[dicObjects valueForKey:K_Rating] andTagValue:intTempCounter];
[mapViewPledgeList addAnnotation:myCustomAnnotation];

MyCustomAnnotation.h

@interface MyCustomAnnotation : NSObject<MKAnnotation>

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (copy, nonatomic) NSString *title;
@property (copy, nonatomic) NSString *subTitle;
@property (copy, nonatomic) NSString *titleDescritpion;
@property (copy, nonatomic) NSString *strImageName;
@property int intTagValue;


- (id)initWithTitle:(NSString *)newTitle Subtitle:(NSString *)subTitle andDescritpion:(NSString *)titleDescritpion withLocation:(CLLocationCoordinate2D)location andTagValue:(int) intTag;
- (MKAnnotationView *)annotationView;
- (id)initWithTitle:(NSString *)newTitle Subtitle:(NSString *)subTitle andDescritpion:(NSString *)titleDescritpion withLocation:(CLLocationCoordinate2D)location andImageName:(NSString*) strImageName andTagValue:(int) intTag;
@end

MyCustomAnnotation.m

#import "MyCustomAnnotation.h"

@implementation MyCustomAnnotation


#pragma mark - Custom Annotation View Setup
- (MKAnnotationView *)annotationView{

MKAnnotationView *annotationView = [[MKAnnotationView alloc]initWithAnnotation:self reuseIdentifier:K_ID_CUSTOM_ANNOTATION];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.image = kImage(_strImageName);

UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
button.frame = CGRectMake(0, 0, 23, 23);
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[button setImage:[[UIImage imageNamed:@"NextArrow"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = button;

return annotationView;
}

- (id)initWithTitle:(NSString *)newTitle Subtitle:(NSString *)subTitle andDescritpion:(NSString *)titleDescritpion withLocation:(CLLocationCoordinate2D)location andImageName:(NSString*) strImageName andTagValue:(int) intTag{

self = [super init];

if(self){
_title = newTitle;
_subTitle = subTitle;
_titleDescritpion = titleDescritpion;
_coordinate = location;


if ([strImageName intValue] == 1) {
_strImageName = @"MapViewPinRed";

}else if([strImageName intValue] == 2){
_strImageName = @"MapViewPinOrange";

}else if ([strImageName intValue] == 3){
_strImageName = @"MapViewPinYellow";

}else if ([strImageName intValue] == 4){
_strImageName = @"MapViewPinLightGreen";

}else{
_strImageName = @"MapViewPinGreen";

}
}

return self;
}

@end

我尝试了以下解决方案,但它不起作用。

1) 使用MKMapRectUnion

 MKMapRect zoomRect = MKMapRectNull;
for (id <MKAnnotation> annotation in mapViewPledgeList.annotations)
{
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0.1, 0.1);
zoomRect = MKMapRectUnion(zoomRect, pointRect);
}
[mapViewPledgeList setVisibleMapRect:zoomRect animated:YES];

2) 使用showAnnotations

 [mapViewPledgeList showAnnotations:mapViewPledgeList.annotations animated:YES];

问题:-建议任何解决方案,以便所有注释对用户可见。

最佳答案

不要忘记在 map 上添加注释。也许这可能是问题所在

[self.mapView addAnnotation:point]; 

关于ios - MKMapView 中的所有 Annotation 对用户不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44156227/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com