Как получить описание для каждого пина, в Google Maps для iPhone - PullRequest
0 голосов
/ 08 ноября 2010

У меня проблема с MKPointAnnotation.Я хочу создать свое приложение для iPhone следующим образом:

  1. Показать пин-код в Google Maps
  2. Показать описание на каждом пин-коде, вытягивая это описание из NSMutableArray.

Итак, мой вопрос: как мне показать описание на каждом штырьке?

Это мой код:

 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];

1 Ответ

0 голосов
/ 08 ноября 2010

Я бы принял протокол MKAnnotation в своем классе и просто переопределил

 - (NSString) title

и внедрить

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

Мой класс также будет иметь инициализатор, который берет все необходимые данные (из массива, который вы упомянули)

- (id) initWithTitle:(NSString *)title_ andLatitude:(CLLocationDegrees)latitude_ andLongitude:(CLLocationDegrees)longitude_;

При переборе я создаю свои собственные объекты, а затем добавляю их в коллекцию аннотаций.

Приветствия ...

...