2011-12-07 12 views
0

確かにこれはマップから始めるだけの簡単なことです。私は既に1つの場所を示す地図を持っていますが、2つ目のアノテーションを追加すると、私の場所に行くのではなく、地図全体がズームしたままになります。ズームインするとピンがそこにありますので、ビットが機能していることがわかります。iOS4 MKMapKit - 1つ以上のピンがズームインされていない場合のマップ

コードスニペット:

- (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; 
} 

私は、任意のポインタをいただければと思います。

また、複数のマップを同時にマップに表示したい場合は、カスタムコールアウトを作成する必要があります。

答えて

0

申し訳ありませんが、答えを見つけました - 私は私のヘッダーファイルにはありますが、私はMKMapViewデリゲートをIBのFile's Ownerにリンクさせていませんでした。リンクして、それが動作している。

関連する問題