2010-11-08 45 views
0

我遇到了MKPointAnnotation的问题。我想这样的创造我的iPhone应用程序:如何在iPhone的谷歌地图中获取每个引脚的描述

  1. 显示在谷歌地图针
  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]; 

回答

0

我会采取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_; 

迭代时,我会创建自己的对象,然后将它们添加到注释集合中。

干杯...

相关问题