1

このようなデータベースにデータがあります。

["{37.331622, -122.030337}","{37.331593, -122.03051}","{37.331554, -122.030681}","{37.331383, -122.030757}","{37.33108, -122.030772}","{37.330798, -122.030729}","{37.330636, -122.030636}"]

次に、次のコードでデータベースからデータをクエリしようとします。

- (void)updateLocations {
    CGFloat kilometers = self.radius/1000.0f;
    //PFUser *user = [PFUser currentUser];
    PFQuery *query = [PFQuery queryWithClassName:@"Session"];
    [query whereKey:@"objectId" equalTo:@"t2udAri048"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            NSLog(@"objects %@",objects);
            NSLog(@"path %@",[objects valueForKey:@"Path"]);
            NSArray *pointsArray = [objects valueForKey:@"Path"];;
            NSInteger pointsCount = pointsArray.count;
            CLLocationCoordinate2D pointsToUse[pointsCount];

            for(int i = 0; i < pointsCount; i++) {
                CGPoint p = CGPointFromString(pointsArray[i]);
                pointsToUse[i] = CLLocationCoordinate2DMake(p.x,p.y);
            }

            MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:pointsToUse count:pointsCount];
            [self.mapView addOverlay:myPolyline];
            //NSLog(@"Drawed %@",pointsArray);
        }
    }];
}

[objects valueForKey:@"Path"] の値を取得します

( ( "{37.331622, -122.030337}", "{37.331593, -122.03051}", "{37.331554, -122.030681}", "{37.331383, -122.030757}", "{37.33108, -122.03,0378" . 、-122.030729}"、"{37.330636、-122.030636}" ) )

しかし、私はそれをしたいです

( "{37.331622, -122.030337}", "{37.331593, -122.03051}", "{37.331554, -122.030681}", "{37.331383, -122.030757}", "{37.33108, -122.03033,"{787}. -122.030729}」、「{37.330636、-122.030636}」)

私は何をすべきか?

4

2 に答える 2

1

「Path」プロパティを持つオブジェクトである 1 つの要素objects配列であるかのように見えます。その場合は交換する必要があります

NSArray *pointsArray = [objects valueForKey:@"Path"];

NSArray *pointsArray = [objects[0] valueForKey:@"Path"];
于 2014-04-13T14:41:18.110 に答える