Come posso contenere tutte le stringa da array?
Domanda
Provo a convertire GeoPoint per array con Geopoint to String to Array.Voglio usare questo array per disegnare polilinea in kit map. Ora posso convertire in stringa ma non posso contenere all'array. Come posso contenere tutte le stringa da array C'è un altro modo per utilizzare GeoPoint per disegnare una polilinea in Kit Map?
- (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);
}
}
}];
}
. Soluzione
È necessario creare un array per aggiungere le corde a.Se si esegue la creazione di un NSMutableArray
e assegnarlo a muarray
, è praticamente aggiunto la stringa a nil
che non fa nulla.
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);
}
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow