0

我正在使用 KML

https://developer.apple.com/library/ios/samplecode/KMLViewer/Listings/Classes_KMLParser_m.html#//apple_ref/doc/uid/DTS40010046-Classes_KMLParser_m-DontLinkElementID_4

它工作得很好,但现在我正在使用MapBox,我需要线坐标来从 KMLViewer 绘制我的路线。我可以在这个函数中看到坐标:

static void strToCoords(NSString *str, CLLocationCoordinate2D **coordsOut, NSUInteger *coordsLenOut)
{
    NSUInteger read = 0, space = 10;
    CLLocationCoordinate2D *coords = malloc(sizeof(CLLocationCoordinate2D) * space);
    NSArray *tuples = [str componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    for (NSString *tuple in tuples)
    {
        if (read == space)
        {
            space *= 2;
            coords = realloc(coords, sizeof(CLLocationCoordinate2D) * space);
        }

        double lat, lon;
        NSScanner *scanner = [[NSScanner alloc] initWithString:tuple];
        [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@","]];
        BOOL success = [scanner scanDouble:&lon];
        if (success)
            success = [scanner scanDouble:&lat];
        if (success)
        {
            NSLog(@"Coordenates: %f %f",lat,lon);
            CLLocationCoordinate2D c = CLLocationCoordinate2DMake(lat, lon);
           if (CLLocationCoordinate2DIsValid(c))
           {
                coords[read++] = c;
           }
        }
    }

    *coordsOut = coords;
    *coordsLenOut = read;
}

如何将坐标提取到我的 viewController?非常感谢!

4

0 回答 0