Domanda

Ho dati sul database come questo.

["{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}"]
.

Quindi provo a interrogare i dati dal database seguendo il codice.

- (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);
        }
    }];
}
.

ottengo il valore di [Oggetti ValoreForkey: @ "percorso"]

.

( ( "{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}" ))

Ma voglio che

.

( "{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}" )

Cosa dovrei fare?

È stato utile?

Soluzione

Sembra che objects sia un array di un elemento, che è un oggetto con il "percorso" proprietà.In tal caso dovresti sostituire

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

di

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

Altri suggerimenti

Nel tuo esempio hai il oggetto.Se questo è il caso, usi GETOBJECTWHID.Questo restituirà solo l'oggetto che desideri.

PFQuery * Query= [PFQuery QueryWithClassName: @ "Sessione"];

[Query GetObjectWithID: @ "HR46GJHH45"];

Il tuo esempio restituisce una matrice di oggetti;In questo caso l'array ha solo un oggetto (ma è ancora un array).In tal caso devi prima recuperare l'oggetto dall'array.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top