我有一个用“,”分隔的经纬度字符串:
NSArray* coord = [newString componentsSeparatedByString:@","];
NSMutableArray *lat= [[NSMutableArray alloc] init];
NSMutableArray *lon = [[NSMutableArray alloc] init];
for(int i=0;i<[coord count]-1;i=i+2)
{
[lat addObject:[coord objectAtIndex:i]];
[lon addObject:[coord objectAtIndex:i+1]];
}
我想将它们与此功能一起使用:
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
{
int i, j, c = 0;
for (i = 0, j = nvert-1; i < nvert; j = i++) {
if ( ((verty[i]>testy) != (verty[j]>testy)) &&
(testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
c = !c;
}
return c;
}
所以 NSMutableArray 不工作。所以我创建了这个:
//Seperating the string with coordinates by ","
NSArray* coord = [newString componentsSeparatedByString:@","];
float *lat = malloc(sizeof(float) * ([coord count]/2));
float *lon = malloc(sizeof(float) * ([coord count]/2));
for(int i=0;i<[coord count]-1;i=i+2)
{
lat[i]= [[coord objectAtIndex:i] floatValue];
lon[i]= [[coord objectAtIndex:i+1] floatValue];
}
free(lat);
free(lon);
这给了我一些错误,例如: (5629,0xacc3da28) malloc: *对象 0x714c490 的错误:已释放对象的校验和不正确 - 对象可能在被释放后被修改。