KMLViewer Stract坐标

时间:2013-09-25 08:43:41

标签: line kml

我正在使用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?非常感谢你!

0 个答案:

没有答案