Comment puis-je contenir l'ensemble de la chaîne de tableau?
Question
J'essaie de convertir GeoPoint à la Matrice par Geopoint de Chaîne à la Matrice.Je veux utiliser ce tableau pour dessiner une polyligne dans le kit de carte.Maintenant, je peux le convertir à la chaîne, mais ne peut pas contenir à la matrice.Comment puis-je contenir l'ensemble de la chaîne de tableau Est-il une autre façon d'utiliser GeoPoint pour dessiner une polyligne dans le kit de carte?
- (void)updateLocations {
CGFloat kilometers = self.radius/1000.0f;
PFQuery *query = [PFQuery queryWithClassName:@"Location"];
[query setLimit:1000];
[query whereKey:@"location"
nearGeoPoint:[PFGeoPoint geoPointWithLatitude:self.location.coordinate.latitude
longitude:self.location.coordinate.longitude]
withinKilometers:kilometers];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
static NSNumberFormatter *numberFormatter = nil;
if (numberFormatter == nil) {
numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
numberFormatter.maximumFractionDigits = 6;
}
//NSArray *path = [objects valueForKey:@"location"]; //dictionary to array!!!
//NSLog(@"%@ %@",objects,path);
NSMutableArray *muarray;
for (PFObject *object in objects) {
PFGeoPoint *geoPoint = object[@"location"];
NSString *string = [NSString stringWithFormat:@"{%@, %@}",
[numberFormatter stringFromNumber:[NSNumber numberWithDouble:geoPoint.latitude]],
[numberFormatter stringFromNumber:[NSNumber numberWithDouble:geoPoint.longitude]]];
NSLog(@"%@",string);
[muarray addObject:string]; //I'm try this but it's fail.
NSLog(@"%@",muarray);
}
}
}];
}
La solution
Vous avez besoin de créer un tableau pour ajouter des cordes.Si tu fais créer un NSMutableArray
et de l'affecter à muarray
vous êtes essentiellement en ajoutant la chaîne d' nil
qui ne fait rien.
NSMutableArray *muarray = [NSMutableArray array];
for (PFObject *object in objects) {
PFGeoPoint *geoPoint = object[@"location"];
NSString *string = [NSString stringWithFormat:@"{%@, %@}",
[numberFormatter stringFromNumber:[NSNumber numberWithDouble:geoPoint.latitude]],
[numberFormatter stringFromNumber:[NSNumber numberWithDouble:geoPoint.longitude]]];
NSLog(@"%@",string);
[muarray addObject:string]; //I'm try this but it's fail.
NSLog(@"%@",muarray);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow