CLLocationCoordinate2D和NSMutableArray

时间:2011-10-05 08:17:29

标签: objective-c ios google-maps geolocation

我有两个NSMutableArray,第一个保留一些位置的纬度,第二个保持经度。然后,我想在地图上用标记看到这个位置。这段代码在地图上显示了一个点,但我在NSMutableArray上有几个点。我怎样才能做到这一点?有人帮我吗?

- (void)viewDidLoad
{
[super viewDidLoad];

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;


CLLocationCoordinate2D location;

location.latitude = 40.182533;
location.longitude = 29.066868;

region.span=span;
region.center=location;

if(addAnnotation != nil) {
    [mapView removeAnnotation:addAnnotation];
    [addAnnotation release];
    addAnnotation = nil;
}

addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
[mapView addAnnotation:addAnnotation];

[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];

// Do any additional setup after loading the view from its nib.

}

1 个答案:

答案 0 :(得分:0)

您需要为每个lat-lon创建注释并添加到mapview。假设您的lat lon数组处于平衡和顺序,算法可以如下所示。

Loop through your lat or lon array

   CLLocationCoordinate2D location;

   location.latitude = latArray[index];
   location.longitude = lonArray[index];

   addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
   [mapView addAnnotation:addAnnotation];

Loop ends