2011-12-07 46 views
0

確定這很簡單,因爲我只是從地圖開始。我已經有一張地圖顯示了一個位置,但是當我添加了第二個地圖時,地圖保持放大狀態,而不是進入我的位置。當我放大時,引腳在那裏,所以我知道那個位正在工作。iOS4 MKMapKit - 地圖在多個針腳時不放大

代碼片段:

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

對不起,找到了答案 - 我沒有在IB中鏈接到文件所有者的MKMapView委託,儘管我的頭文件中有。鏈接起來,它的工作。

相關問題