0

我正在解析这个 JSON 文件(正确地,它适用于 UITextFields):

{"longitude":["37.786793","39.388528"],"latitude":["-122.395416","-78.887734"]}

ind 创建 MapViews,并以这种方式使用相应的注释:

NSArray *allKeys2 = [DictionaryMap allKeys];

for (int h = 0; h < [allKeys2 count]; h++) {


CGRect mapFrame = CGRectMake( 400, e, 200, 110);

MKMapView *mapView2 = [[MKMapView alloc] initWithFrame:mapFrame];
[image1 addSubview:mapView2]; 







    NSString *key2 = [allKeys2 objectAtIndex:i];
    NSObject *obj2 = [DictionaryMap objectForKey:key2];




    NSString *address = [NSString stringWithFormat:@"%@", obj2];
    float stringFloat = [address floatValue];
    float stringFloat2 = [key2 floatValue];

    CLLocationCoordinate2D anyLocation;

    anyLocation.longitude = stringFloat;

    anyLocation.latitude  = stringFloat2;







    MKPointAnnotation *annotationPoint2 = [[MKPointAnnotation alloc] init]; annotationPoint2.coordinate = anyLocation;

    annotationPoint2.title = @"Event";
    annotationPoint2.subtitle = @"Microsoft's headquarters2";
    [mapView2 addAnnotation:annotationPoint2];  


    [mapView2.userLocation setTitle:@"I am here"];

    [mapView2.userLocation addObserver:self  
                                 forKeyPath:@"location"  
                                    options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)

                                    context:NULL];

    [mapView2 setShowsUserLocation:NO];

    [MapViewArray addObject:mapView2];

    if (MapViewArray == nil)MapViewArray = [[NSMutableArray alloc]init];
    [MapViewArray addObject: mapView2];


     }}

}while(g < f); 

...我希望第一个地图视图显示第一个坐标图钉,第二个显示第二对坐标。但是现在,它在所有地图视图上绘制相同的图钉,对应于最后一个坐标,而不是分别对应于第一个和第二个……。此方法适用于 UITextField 文本,所以我找不到问题。

请帮忙!!

编辑:

NSString *filenameMap = [NSString stringWithFormat:@"%@%@Map", destDir, NavBar.topItem.title];

NSString *MapPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@Map", NavBar.topItem.title]];

[self.restClient loadFile:filenameMap intoPath:MapPath];


NSString *fileContentMap = [[NSString alloc] initWithContentsOfFile:MapPath];  

SBJsonParser *parserMap = [[SBJsonParser alloc] init];

NSDictionary *dataMap = (NSDictionary *) [parserMap objectWithString:fileContentMap error:nil];  


NSArray *MaparrayLongitude = [dataMap objectForKey:@"longitude"];
NSArray *MaparrayLatitude = [dataMap objectForKey:@"latitude"];


NSDictionary* DictionaryMap = [NSDictionary dictionaryWithObjects:MaparrayLatitude forKeys:MaparrayLongitude];
4

1 回答 1

0

另一种做法:

您可能不想在 DictionaryMap 中将纬度映射到经度。如何制作一个 NSDictionaries 的 NSArray,其中每个字典都有一个“纬度”键和一个“经度”键?

此外,您的代码中有两次“[MapViewArray addObject: mapView2]”。

And what is "g"? Maybe add some logging to your loop so you can see what's being created?

于 2012-06-27T00:24:11.803 回答