0

この JSON ファイルを解析しています (正しく、UITextFields で動作します)。

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

次のように、それぞれの注釈を使用して MapView を作成します。

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); 

...最初のマップ ビューに最初の座標ピンを表示し、2 番目のマップ ビューに 2 番目の座標ピンを表示します。しかし今では、すべてのマップ ビューに同じピンがプロットされています。これは、最初と 2 番目の座標ではなく、それぞれ最後の座標に対応しています。このメソッドは 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]」が 2 回含まれています。

そして、「g」とは何ですか?ループにログを追加して、何が作成されているかを確認できますか?

于 2012-06-27T00:24:11.803 に答える