-4

我想访问纬度和经度的坐标值。

    NSString *path = [[NSBundle mainBundle] pathForResource:
                      @"WellList" ofType:@"plist"];
    NSMutableArray *cities = [[NSMutableArray alloc] initWithContentsOfFile:path];
    NSDictionary *routes =[[NSDictionary alloc]initWithContentsOfFile:path];
    NSDictionary *city =[[NSDictionary alloc]init];
    NSDictionary *locations =[[NSDictionary alloc]init];
    NSDictionary *locationInfo=[[NSDictionary alloc]init];

    NSMutableArray *localCities= [[NSMutableArray alloc]init];
    city= routes [@"Routes"];
    NSLog (@"%@",city);
    localCities =[[NSMutableArray alloc] initWithArray:[city allValues]];
    locations =[localCities objectAtIndex:1];

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

1

我认为您的问题是您不了解加载 .plist 文件的工作原理。Routes 和 Cities 被初始化为相同的值,因为您正在从同一个文件加载它们。因此,要访问休斯顿位置 1 的纬度,您可以编写

NSMutableDictionary *root = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

NSString* latitude = [[[[[root objectForKey: @"Routes"] objectForKey: @"Houston" ] objectForKey: @"Location 1"] objectForKey: @"coordinate"] objectForKey: @"latitude"]; 
于 2013-07-19T17:18:58.530 回答