2012-01-28 30 views
1

我剛剛創建了一個新的應用程序,我已經實現了在一個視圖中的地圖。 我已經用一些個人註釋創建了地圖,但是當用戶觸摸該圖釘時,沒有出現任何東西。我試圖設置針的顏色,但似乎沒有任何工作。我需要用戶在觸摸引腳時可以觸摸彈出窗口上的揭示按鈕,以使用「原生地圖」。 現在,當我觸摸針時,這一個變得更暗,但沒有別的。 有人可以幫我嗎?請!!Mapkit用針新的註解,而不彈出

IO NE avrei bisogno,每遠aprire POI未公開Ë遠aprire L'應用nativa mappe每creare IL percorso !! Se ora tocco il pin,questo diventapiùscuro ma non succede nulla! non riesco nemmeno ad agire su di loro per cambiare colore,immagini,.... ho guardato i tutorial ma non trovo l'errore!

頭子類

#import <Foundation/Foundation.h> 
    #import <MapKit/Mapkit.h> 

    @interface myAnnotation : NSObject <MKAnnotation>{ 

     CLLocationCoordinate2D coordinate; 
     NSString *titolo; 
     NSString *sottotitolo; 
    } 

    @property(nonatomic,assign) CLLocationCoordinate2D coordinate; 
    @property(nonatomic,copy) NSString *titolo; 
    @property(nonatomic,copy) NSString *sottotitolo; 


    @end 

實現子類

@implementation myAnnotation 

    @synthesize titolo; 
    @synthesize sottotitolo; 
    @synthesize coordinate; 

    -init{ 
     return self; 

    } 

    @end 

文件的.m視圖控制器

CLLocation *userLoc = myMapView.userLocation.location; 
     CLLocationCoordinate2D userCoordinate = userLoc.coordinate; 
     NSLog(@"user latitude = %f",userCoordinate.latitude); 
     NSLog(@"user longitude = %f",userCoordinate.longitude); 
     myMapView.delegate=self; 


     NSMutableArray* annotations=[[NSMutableArray alloc] init]; 

     CLLocationCoordinate2D theCoordinate1; 
     theCoordinate1.latitude = 45.; 
     theCoordinate1.longitude = 7.; 

     CLLocationCoordinate2D theCoordinate2; 
     theCoordinate2.latitude = 45.; 
     theCoordinate2.longitude = 12.; 

     CLLocationCoordinate2D theCoordinate3; 
     theCoordinate3.latitude = 45.; 
     theCoordinate3.longitude = 8.; 

     CLLocationCoordinate2D theCoordinate4; 
     theCoordinate4.latitude = 43.; 
     theCoordinate4.longitude = 7.; 

     myAnnotation* myAnnotation1=[[myAnnotation alloc] init]; 

     myAnnotation1.coordinate=theCoordinate1; 
     [email protected]"xxxx"; 
     [email protected]"xxx"; 


     myAnnotation* myAnnotation2=[[myAnnotation alloc] init]; 

     myAnnotation2.coordinate=theCoordinate2; 
     [email protected]"yyyy"; 
     [email protected]"yyyy"; 

     myAnnotation* myAnnotation3=[[myAnnotation alloc] init]; 

     myAnnotation3.coordinate=theCoordinate3; 
     [email protected]"zzz"; 
     [email protected]"zzz"; 

     myAnnotation* myAnnotation4=[[myAnnotation alloc] init]; 

     myAnnotation4.coordinate=theCoordinate4; 
     [email protected]"kkk"; 
     [email protected]"kkk"; 


     [myMapView addAnnotation:myAnnotation1]; 
     [myMapView addAnnotation:myAnnotation2]; 
     [myMapView addAnnotation:myAnnotation3]; 
     [myMapView addAnnotation:myAnnotation4]; 


     [annotations addObject:myAnnotation1]; 
     [annotations addObject:myAnnotation2]; 
     [annotations addObject:myAnnotation3]; 
     [annotations addObject:myAnnotation4]; 


     NSLog(@"%d",[annotations count]); 

,然後將該片段以顯示和個性化的銷

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: 
(id <MKAnnotation>)annotation { 
    MKPinAnnotationView *pinView = nil; 
    if(annotation != mapView.userLocation) 
    { 
     static NSString *defaultPinID = @"com.invasivecode.pin"; 
     pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
     if (pinView == nil) pinView = [[[MKPinAnnotationView alloc] 
              initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease]; 

     pinView.pinColor = MKPinAnnotationColorPurple; 
     pinView.canShowCallout = YES; 
     pinView.animatesDrop = YES; 
    } 
    else { 
     [mapView.userLocation setTitle:@"I am here"]; 
    } 
    return pinView; 
} 

回答

3

MKAnnotation協議要求類響應titlesubtitle。這些屬性必須完全像這樣命名。

儘管您也可以爲自己命名屬性不同,但地圖視圖不會調用它們(它正在尋找titlesubtitle)。

對於披露按鈕,在viewForAnnotation中,將rightCalloutAccessoryView設置爲UIButton,並在calloutAccessoryControlTapped委託方法中響應其點擊。

在該委託方法中,您可以使用(myAnnotation *)view.annotation訪問註釋對象,然後致電openURL來打開地圖應用程序。

+0

感謝安娜·卡列尼娜!你已經解決了這個問題! :) – TheInterestedOne 2012-01-30 10:54:11