2010-11-08 14 views
0

J'ai un problème avec MKPointAnnotation. Je veux créer mon application iPhone comme ceci:Comment obtenir une description pour chaque épingle, dans Google Maps pour l'iPhone

  1. Afficher une épingle dans Google Maps
  2. Afficher une description sur chaque broche, tirant cette description d'un NSMutableArray.

Alors, Ma question est, comment puis-je afficher une description sur chaque broche?

Ceci est mon code:

NSMutableArray *points = [[NSMutableArray alloc] init]; 
for(int i=0; i < [dataTable count]; i++) { 
    MKPointAnnotation *point =[[MKPointAnnotation alloc] init]; 
    CLLocationCoordinate2D coordinate; 
    coordinate.latitude = [[[dataTable objectAtIndex:i] objectForKey:@"latitude"] floatValue]; 
    coordinate.longitude = [[[dataTable objectAtIndex:i] objectForKey:@"longitude"] floatValue]; 
    [point setCoordinate:coordinate]; 
    [point setTitle:[[dataTable objectAtIndex:i] objectForKey:@"name"]]; //-- name of pin 
    [points addObject:point]; 
} 
[map addAnnotations:points]; 

Répondre

0

J'adopte le protocole MKAnnotation dans ma propre classe et simplement remplacer le

- (NSString) title 

et mettre en œuvre

- (CLLocationCoordinate2D) coordinate { 
    CLLocationCoordinate2D theCoordinate; 
    theCoordinate.latitude = self.latitude; 
    theCoordinate.longitude = self.longitude; 
    return theCoordinate; 
} 

Ma classe serait également avoir un initialiseur qui prend toutes les données dont il a besoin (du tableau que vous avez mentionné)Lors de l'itération, je créerais mes propres objets, puis les ajouterais à la collection d'annotations.

Cheers ...