「、」で区切られた緯度と経度の文字列があります。
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: * error for object 0x714c490: 解放されたオブジェクトのチェックサムが正しくありません - オブジェクトは解放後に変更された可能性があります。