문제

GeoPoint를 String으로, GeoPoint를 Array로 변환하려고 합니다.지도 키트에서 폴리라인을 그리는 데 이 배열을 사용하고 싶습니다.이제 문자열로 변환할 수 있지만 배열로 포함할 수는 없습니다.모든 문자열을 배열에 포함하려면 geopoint를 사용하여지도 키트에 폴리 라인을 그리는 또 다른 방법이 있습니까?

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


            }
        }
    }];
}
도움이 되었습니까?

해결책

문자열을 추가할 배열을 만들어야 합니다.당신이 만들고 있다면 NSMutableArray 그리고 그것을 할당 muarray 기본적으로 문자열을 추가하고 있습니다. nil 아무것도하지 않습니다.

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


        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top