Question

I try to convert GeoPoint to Array by Geopoint to String to Array. I want to use this array for draw polyline in map kit. Now i can convert to string but can't contain to array. How can i contain all string to array Is there another way to use GeoPoint to draw a polyline in map kit?

- (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);


            }
        }
    }];
}
Was it helpful?

Solution

You need to create an array to add the strings to. If you doing create a NSMutableArray and assign it to muarray you're basically adding the string to nil which does nothing.

        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);


        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top