我正在使用KML
它工作得很好,但现在我正在使用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?非常感谢你!