0

您好,感谢您的帮助。

是否可以使用 for 循环从 .plist 文件中填充 10 个地图视图位置?如果有怎么办?

我当前的地图视图代码都是硬编码的。如果可能的话,我想通过从 for 循环中提取经度、纬度、标题、子标题来改进这一点。谢谢你。

  ////
.....
                MKCoordinateRegion region3 = {{0.0,0.0}, {0.0,0.0}};

                region3.center.latitude = 33.45869;
                region3.center.longitude = -84.66931;
                region3.span.longitudeDelta = 0.01f;
                region3.span.latitudeDelta=0.01f;
                //  [mapview setRegion:region4 animated:YES];

                BandsMap *ann3 = [[BandsMap alloc]init];
                ann3.title = @"Indigo Bar & Lounge";
                ann3.subtitle = @"Let the good times roll";
                ann3.coordinate = region3.center;//

            //// 


                annoArray = [[NSArray alloc] initWithObjects:ann1,ann2,ann3.....,nil];


                [mapView addAnnotations:annoArray];.......

我想是这样的,但不太确定如何完成

        for(NSDictionary *key in mapDataPlist)
            {
                    NSString *c = [key objectForKey:@"Title"];
                NSString *a = [key objectForKey:@"SubTitle"];
                NSString *lat = [key objectForKey:@"Latitude"];
                NSString *lon = [key objectForKey:@"Longitude"];

                CGFloat strFLat = (CGFloat)[lat floatValue];
                CGFloat strFLon = (CGFloat)[lon floatValue];

//////

?????

             }
4

2 回答 2

0

只需遍历您的 plist 数组并使用您必须从提取的数据创建区域的代码。然后,annoArray与其在最后创建一个数组,不如让它成为一个可变数组,并在每次循环迭代结束时添加每个项目。

于 2013-07-16T17:36:12.223 回答
0
[mapView setRegion:adjustedRegion animated:YES];
    mapView.mapType=MKMapTypeStandard;
    UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.frame = CGRectMake(28, 60, 334, 649);
    [self.view addSubview:tableView];


    NSString *path = [[NSBundle mainBundle] pathForResource:
                      @"CityList" ofType:@"plist"];
    NSMutableArray *cities = [[NSMutableArray alloc] initWithContentsOfFile:path];
    NSMutableArray *localCities= [[NSMutableArray alloc]init];
    for (int i=0;i<[cities count];i++)
    {
    NSLog(@"%@",[[cities objectAtIndex:i]objectForKey:@"cityNameKey"]);

        [localCities addObject:[[cities objectAtIndex:i]objectForKey:@"cityNameKey"]];
    }


    locationArray= localCities;

    Annotation *annotation=[[Annotation alloc]init];
    annotation.coordinate = CLLocationCoordinate2DMake(29.7631,-95.3631);
    annotation.color = [UIColor redColor];
    annotation.title=[NSString stringWithFormat:@"Houston"];
    [mapView addAnnotation:annotation];
于 2013-07-17T17:17:02.273 回答