Perhaps the CoreLocation infrastructure can help you solve this problem? Your question seems to have made the following method:
- (id)initCircularRegionWithCenter:(CLLocationCoordinate2D)center radius:(CLLocationDistance)radius identifier:(NSString *)identifier
You can check if the coordinate from your database falls into the area using the following method:
- (BOOL)containsCoordinate:(CLLocationCoordinate2D)coordinate
I think this is not ideal if there are many places in your database. But perhaps you can filter out a set of locations for testing based on the minimum and maximum latitude / longitude values.
Edit: as requested, example (don't forget to import the CoreLocation environment):
- (void)startTest { #define COORDS_COUNT 4 #define RADIUS 10000.0f CLLocationCoordinate2D coords[COORDS_COUNT] = { CLLocationCoordinate2DMake(52.000004, 4.100002), CLLocationCoordinate2DMake(53.000009, 4.000003), CLLocationCoordinate2DMake(52.000001, 4.500008), CLLocationCoordinate2DMake(52.000002, 3.900900), }; CLLocationCoordinate2D center = CLLocationCoordinate2DMake(52.0f, 4.0f); // Amsterdam CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:center radius:RADIUS identifier:@"Amsterdam"]; for (int i = 0; i < COORDS_COUNT; i++) { CLLocationCoordinate2D coord = coords[i]; if ([region containsCoordinate:coord]) { NSLog(@"location %f, %f is within %.0f meters of coord %f, %f", coord.latitude, coord.longitude, RADIUS, center.latitude, center.longitude); } else { NSLog(@"location %f, %f is not within %.0f meters of coord %f, %f", coord.latitude, coord.longitude, RADIUS, center.latitude, center.longitude); } } }
Edit 2: I understand that this is not the answer you asked, but it seems to me that this is what you need. As you can imagine, the nearest 100-meter latitude / longitude near any coordinate consists of an almost unlimited number of coordinates in a circular area. I assume that you want to find objects in your database that are near some coordinate, and the above code should help you with this. You can get a set of results from your database and check if they are near some coordinate.
Edit 3: The following code is most likely exactly what you need:
CLLocation *center = [[CLLocation alloc] initWithLatitude:52.0f longitude:4.0f];
Edit 4: regarding your question about a custom object to represent a table, use something like the following:
@interface Location : NSObject @property (nonatomic, strong) NSString *name; @property (nonatomic, assign) CLLocationCoordinate2D coordinate; @end @implementation Location @synthesize name, coordinate; @end