iOS4 MKMapKit - 当多个引脚时,映射不放大

时间:2011-12-07 12:02:14

标签: ios4 mkmapview

当然,我只是从地图开始,这很简单。我已经有了一个显示一个位置的地图,但是当我添加了第二个anotation时,地图会一直保持缩放而不是去我的位置。当我放大时,引脚就在那里,所以我知道那个位正在工作。

代码段:

- (void)viewDidLoad
{
...
...
...

// Set coordinates for our position
CLLocationCoordinate2D location;
location.latitude = [self.lat doubleValue];
location.longitude = [self.lon doubleValue];

// Add the annotation to our map view
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] 
                                    initWithTitle:self.placename                                        
                                    andSubtitle:self.subtitle
                                    andCoordinate:location];
[self.mapView addAnnotation:newAnnotation];
[newAnnotation release];

// Set coordinates for our second position
CLLocationCoordinate2D amenitylocation;
amenitylocation.latitude = self.latitude;
amenitylocation.longitude = self.longitude;

// Add the annotation to our map view
MapViewAnnotation *amenityAnnotation = [[MapViewAnnotation alloc] 
                                    initWithTitle:self.callouttitle                                        
                                    andSubtitle:self.calloutsubtitle
                                    andCoordinate:amenitylocation];
[self.mapView addAnnotation:amenityAnnotation];
[amenityAnnotation release];

[super viewDidLoad];

}



#pragma mark - MKMapView Delegates

// When a map annotation point is added, zoom to it (1500 range)
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500);
[mv setRegion:region animated:YES];
[mv selectAnnotation:mp animated:YES];
}

- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id<MKAnnotation>)annotation
{
if(mapView.userLocation==annotation)
{
    return nil;
}

NSString *identifier = @"IDENTIFIER";

MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

if(annotationView==nil)
{
    annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]autorelease];
    annotationView.pinColor=MKPinAnnotationColorPurple;
    annotationView.canShowCallout=YES;
}

return annotationView;
}

我很感激任何指示。

另外,我是否正确地认为如果我希望同时在地图上出现多个自定义标注,我必须制作自定义标注?

1 个答案:

答案 0 :(得分:0)

抱歉,找到了答案 - 我没有将IBMapView委托链接到IB中的文件所有者,尽管我的头文件中有。把它联系起来并且它正在工作。