Ваша задача, как мне кажется, это задача Point-in-polygon (PIP) [https://en.wikipedia.org/wiki/Point_in_polygon]
Чтобы достичь желаемого, вы можете использовать «Алгоритм приведения лучей»
Я сделал довольно быструю реализацию этого алгоритма, чтобы вы могли начать с этого
@implementation PointInRegion
+(NSMutableArray*)getAvailableAddress {
NSMutableArray* dhakaAvailableAreas=[[NSMutableArray alloc]init];
NSDictionary *latLongDict = @{@"lat" : @(23.665217), @"long":@(90.456556)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.710108), @"long":@(90.400022)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.707796), @"long":@(90.366647)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.744056), @"long":@(90.345334)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.751866), @"long":@(90.333149)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.768038), @"long":@(23.768038)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.774732), @"long":@(90.336199)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.796483), @"long":@(90.338031)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.833850), @"long":@(90.339256)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.853928), @"long":@(90.342309)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.867869), @"long":@(90.351460)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.887389), @"long":@(90.358176)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.899096), @"long":@(90.380142)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.882914), @"long":@(90.394773)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.886806), @"long":@(90.417956)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.899729), @"long":@(90.440122)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.895324), @"long":@(90.456267)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.861075), @"long":@(90.475134)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.840659), @"long":@(90.473056)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.828086), @"long":@(90.486782)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.793225), @"long":@(90.480572)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.782239), @"long":@(90.470264)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.770608), @"long":@(90.482614)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.753955), @"long":@(90.488093)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.747045), @"long":@(90.486714)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.742954), @"long":@(90.494262)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.732360), @"long":@(90.493535)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.717059), @"long":@(90.500136)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.710997), @"long":@(90.508137)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.710997), @"long":@(90.508137)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.693175), @"long":@(90.480623)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.672433), @"long":@(90.468799)};
[dhakaAvailableAreas addObject:latLongDict];
latLongDict = @{@"lat" : @(23.667661), @"long":@(90.458352)};
[dhakaAvailableAreas addObject:latLongDict];
return dhakaAvailableAreas;
}
+ (BOOL)checkIfPoint:(CLLocationCoordinate2D)point inRegion:(NSArray<NSDictionary<NSString *, NSNumber *> *> *)region {
int intersectionsCount = 0;
for (int i = 1; i < region.count; i++) {
double lat1 = region[i - 1][@"lat"].doubleValue;
double long1 = region[i - 1][@"long"].doubleValue;
double lat2 = region[i][@"lat"].doubleValue;
double long2 = region[i][@"lat"].doubleValue;
CLLocationCoordinate2D point1;
point1.latitude = lat1;
point1.longitude = long1;
CLLocationCoordinate2D point2;
point2.latitude = lat2;
point2.longitude = long2;
BOOL intersects = [PointInRegion checkIfHorizontalVectorFromPoint:point intersectsEdge:point1 edgePoint2:point2];
if (intersects) {
intersectionsCount++;
}
}
return intersectionsCount % 2 > 0;
}
+ (BOOL)checkIfHorizontalVectorFromPoint:(CLLocationCoordinate2D)point intersectsEdge:(CLLocationCoordinate2D)edgePoint1 edgePoint2:(CLLocationCoordinate2D)edgePoint2 {
double lat = point.latitude;
double longitude = point.longitude;
double lat1 = edgePoint1.latitude;
double long1 = edgePoint1.longitude;
double lat2 = edgePoint2.latitude;
double long2 = edgePoint2.longitude;
if ( lat1 - lat2 == 0 ) {
// Horizontal line
return NO;
}
double x = ((long1 - long2) * lat - (long1 * lat2 - long2 * lat1)) / (lat1 - lat2);
if (longitude < x) {
// Intersection point lies not on the vector
return NO;
}
double diff1 = lat1 - lat;
double diff2 = lat2 - lat;
if (fmax(diff1, diff2) > 0 && fmin(diff1, diff2) < 0) {
// Points lie in different sides
return YES;
}
return NO;
}
@end
Вы можете использовать код, подобный следующему:
CLLocationCoordinate2D point;
point.latitude = 23.665219;
point.longitude = 90.400023;
[PointInRegion checkIfPoint:(CLLocationCoordinate2D)point inRegion:
[PointInRegion getAvailableAddress]];