如何创建CLLocationCoordinate2d对象

时间:2013-06-26 08:28:00

标签: iphone ios cllocationmanager

我正在尝试调用MKPolylines的+ polylineWithCoordinates:count:方法。

在这种情况下,如何创建CLLocationCoordinate2D *对象。我在CLLocationCoordinate2D without knowing how many will be in the array?

中完成了这个特定的答案
// unpacking an array of NSValues into memory
CLLocationCoordinate2D *points = malloc([mutablePoints count] * sizeof(CLLocationCoordinate2D));
for(int i = 0; i < [mutablePoints count]; i++) {
[[mutablePoints objectAtIndex:i] getValue:(points + i)];
}

MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:points count:[mutablePoints count]];
free(points);

在上述情况下,数组mutablePoints中有哪些条目?

2 个答案:

答案 0 :(得分:0)

如果您的问题只是阵列中的条目类型,答案很简单:NSValue个条目。您可以查看此guide,了解有关如何使用NSValues的更多信息。

答案 1 :(得分:0)

CLLocationCoordinate2D coordinate;
    for (int i = 0; i < arr.count; i++)
    {
        float t1 = [[arr objectAtIndex:1] floatValue];
        float t2 = [[arr objectAtIndex:0] floatValue];

        coordinate.latitude = t1;
        coordinate.longitude = t2;

    }