用户在 MKMapView 中看不到所有注释 [英] All Annotation is not visible to user in MKMapView

查看:31
本文介绍了用户在 MKMapView 中看不到所有注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MKMapView 并在地图上添加了许多注释图钉.所有注释都属于不同的国家/地区,因此我无法设置用户可见的所有注释.

I am using MKMapView and have added a number of annotation pins to the map. All annotation belong to different country, so i do not able to set all annotation visible to user.

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

Please do try using below latitude and longitude for annotation.

第一个注释纬度:23.029690

第一个注解经度: 72.527359

第二个注解纬度:34.210855

第二个注解经度: -118.622636

Second annotation Longitude: -118.622636

用于向地图视图添加注释的代码.

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];

问题:-建议任何解决方案,以便用户可以看到所有注释.

Issue:- suggest any solution so all annotation keep visible to user.

推荐答案

Q] 所有注解对用户可见.

Q] All annotation keep visible to user.

  • 遗憾的是,无法将最小缩放级别设置为低于 MKMapView 最小限制.

  • Unfortunately, it is not possible to set minimum zoom level less then the MKMapView minimum limit.

同样在苹果官方地图应用中下方的点是不可见的

Also in apple official map application below point is not visible at same time

第一个注释纬度:23.029690

第一个注解经度: 72.527359

第二个注解纬度: 34.210855

第二个注解经度: -118.622636

Second annotation Longitude: -118.622636

注意:我们无法在达到最低限制后放大地图视图.

这篇关于用户在 MKMapView 中看不到所有注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆