如何在目标c中显示地图上的多个位置点

时间:2011-10-17 06:43:12

标签: objective-c map nsmutablearray

我有两个NSMutableArray,第一个保留一些位置的纬度,第二个保持经度。然后,我想在地图上用标记看到这个位置。我尝试这样但是它不起作用。我怎么能这样做?

    for (int x=0; x<=[ws8.Latitude count]; x++) {
    for (int y=0; y<=[ws8.Longitude count]; y++) {

        CLLocationCoordinate2D location1;

        location1.latitude = [[ws8.Latitude objectAtIndex:x] floatValue];
        location1.longitude = [[ws8.Longitude objectAtIndex:y] floatValue];


        region.span=span;
        region.center=location1;

        if(addAnnotation != nil) {
            [mapView removeAnnotation:addAnnotation];
            [addAnnotation release];
            addAnnotation = nil;
        }
        addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location1];
        [mapView addAnnotation:addAnnotation];
        [mapView setRegion:region animated:TRUE];
        [mapView regionThatFits:region];
        [mapView setShowsUserLocation:YES];
    }
}    

1 个答案:

答案 0 :(得分:0)

对于每个纬度,您使用经度进行映射。我删除了内循环。你能尝试下面的代码,看看它是否适合你?

for (int x=0; x<=[ws8.Latitude count]; x++) {
    CLLocationCoordinate2D location1;

    location1.latitude = [[ws8.Latitude objectAtIndex:x] floatValue];
    location1.longitude = [[ws8.Longitude objectAtIndex:x] floatValue];


    region.span=span;
    region.center=location1;

//        if(addAnnotation != nil) {
//            [mapView removeAnnotation:addAnnotation];
//            [addAnnotation release];
//            addAnnotation = nil;
//        }
    addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location1];
    [mapView addAnnotation:addAnnotation];
    [addAnnotation release];
    [mapView setRegion:region animated:TRUE];
    [mapView regionThatFits:region];
}


[mapView setShowsUserLocation:YES];