한 가지 방법은 다음과 같습니다
1))
2 geoJson
으로 Shape 파일을 변환 코드에서 geoJson 파일 데이터를로드합니다. 이러한 GPS 지점에서
3) 만드는 다각형 (주 : CountryDetectorController 내 컨트롤러 클래스)
+ (MKPolygon *)overlaysFromPolygons:(NSArray *)polygons title:(NSString *)title;
{
NSMutableArray *interiorPolygons = [NSMutableArray arrayWithCapacity:[polygons count] - 1];
for (int i = 1; i < [polygons count]; i++) {
[interiorPolygons addObject:[CountryDetectorController polygonFromPoints:polygons[i] interiorPolygons:nil]];
}
MKPolygon *overlayPolygon = [CountryDetectorController polygonFromPoints:polygons[0] interiorPolygons:interiorPolygons];
overlayPolygon.title = title;
return overlayPolygon;
}
+ (MKPolygon *)polygonFromPoints:(NSArray *)points interiorPolygons:(NSArray *)polygons;
{
NSInteger numberOfCoordinates = [points count];
CLLocationCoordinate2D *polygonPoints = malloc(numberOfCoordinates * sizeof(CLLocationCoordinate2D));
NSInteger index = 0;
for (NSArray *pointArray in points) {
polygonPoints[index] = CLLocationCoordinate2DMake([pointArray[1] floatValue], [pointArray[0] floatValue]);
index++;
}
MKPolygon *polygon;
if (polygons) {
polygon = [MKPolygon polygonWithCoordinates:polygonPoints count:numberOfCoordinates interiorPolygons:polygons];
} else {
polygon = [MKPolygon polygonWithCoordinates:polygonPoints count:numberOfCoordinates];
}
free(polygonPoints);
return polygon;
}
4) 다각형
+ (CGPathRef)pathForPolygon:(MKPolygon*)aPolygon;
{
CGMutablePathRef mpr = CGPathCreateMutable();
MKMapPoint *polygonPoints = aPolygon.points;
size_t nCount = aPolygon.pointCount;
for (int p = 0; p < nCount; p++)
{
MKMapPoint mp = polygonPoints[p];
if (p == 0)
CGPathMoveToPoint(mpr, NULL, mp.x, mp.y);
else
CGPathAddLineToPoint(mpr, NULL, mp.x, mp.y);
}
return mpr; //Keep in memory;
}
5에서 CGPath을 만들 수)에 좌표 있는지 확인하다 CGPath (pathsBelgium은 CGPaths의 NSValue가있는 배열입니다.)
- (void)checkCoordinate:(CLLocationCoordinate2D)coordinate;
{
MKMapPoint mapPoint = MKMapPointForCoordinate(coordinate);
CGPoint mapPointAsCGP = CGPointMake(mapPoint.x, mapPoint.y);
BOOL userIsInBelgium = FALSE;
for(NSValue *valuePathBE in pathsBelgium)
{
CGPathRef pathBe;
[valuePathBE getValue:&pathBe];
BOOL pointInBelgium = CGPathContainsPoint(pathBe, NULL, mapPointAsCGP, FALSE);
if(pointInBelgium)
{
userIsInBelgium = TRUE;
break;
}
}
NSLog(@"User is in Belgium: %i", userIsInBelgium);
}
고맙지 만 사용하지 않고 API 호출. 여기서 인터넷은 다른 웹 서비스에 대한 호출없이 사용됩니다. 이유는 데이터 트래픽을 가능한 한 낮게 유지하기 (해외 데이터 트래픽)이며 인터넷 없이도 작동해야한다는 것입니다. –
죄송합니다. 이 작업에 대한 데이터 트래픽은 매우 적지 만 충분히 공정 할 것입니다. – shim
사용자가 벨기에/네덜란드에 있는지 아닌지에 대해서만 신경을 씁니까, 그렇지 않은 경우 사용자가 전혀 신경 쓰지 않습니까? 그렇다면 각 국경에서 가장 먼 지점까지 근접성을 테스트 할 수 있습니다. – shim