¿Cómo puedo contener todas las cadenas en una matriz?
Pregunta
Intento convertir GeoPoint a Array mediante Geopoint a String to Array.Quiero usar esta matriz para dibujar polilíneas en el kit de mapas.Ahora puedo convertir a cadena pero no puedo contener una matriz.¿Cómo puedo contener toda la cadena a la matriz?
- (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);
}
}
}];
}
Solución
Necesita crear una matriz para agregar las cadenas.Si creas un NSMutableArray
y asignarlo a muarray
básicamente estás agregando la cadena a nil
que no hace nada.
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);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow