Ниже приведен код, который я использую, чтобы проверить, находятся ли широты и долготы в пределах радиуса 100 метров,
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [dataArray count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
Person *temp = (Person *)[self.persons objectAtIndex:indexPath.row];
cell.textLabel.text = temp.strName;
// Configure the cell...
return cell;
}
- (void) readDataFromDatabase{
sqlite3 *database;
persons = [[NSMutableArray alloc]init];
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK){
const char *sqlStatement = "select * from sdata";
sqlite3_stmt *compiledStatement;
if (sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK){
while (sqlite3_step(compiledStatement) == SQLITE_ROW) {
pID = sqlite3_column_int(compiledStatement, 0);
// NSLog(@" Id : %d",pID);
pName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSLog(@" Name : %@",pName);
pAdd = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSLog(@" Address : %@",pAdd);
pPh = sqlite3_column_int(compiledStatement, 3);
NSLog(@" PhoneNo : %d",pPh);
pCp = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)];
NSLog(@" ContactPerson : %@",pCp);
pLat = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)];
NSLog(@" Latitude : %@",pLat);
pLong = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)];
NSLog(@" Longitude : %@",pLong);
Person *temp = [[Person alloc]initWithID:pID name:pName address:pAdd phone:pPh contactperson:pCp fLat:pLat fLong:pLong];
[persons addObject:temp];
[temp release];
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
- (void)startTest
{
for(int j=0;j<[persons count];j++){
Person *arr = [persons objectAtIndex:j];
NSString *s = [[NSString alloc]initWithFormat:@"%@ %@ %@",arr.fLat,arr.fLong,arr.strName] ;
// NSLog(@" data in array : %@", s);
#define COORDS_COUNT 1
#define RADIUS 100.0f
CLLocationCoordinate2D coords[COORDS_COUNT] = {
CLLocationCoordinate2DMake([arr.fLat floatValue], [arr.fLong floatValue ]),
};
CLLocationCoordinate2D center = CLLocationCoordinate2DMake([lat floatValue], [longt floatValue]);
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:center radius:RADIUS identifier:@"Banashankari"];
for (int i = 0; i < COORDS_COUNT; i++)
{
CLLocationCoordinate2D coord = coords[i];
NSString *coordString = [NSString stringWithFormat:@"%f,%f",coord.latitude, coord.longitude];
[dataArray addObject:coordString];
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);
[resultArray addObject:coordString];
NSLog(@"data within 100 meters %@",resultArray);
}
else
{
NSLog(@"location %f, %f is not within %.0f meters of coord %f, %f", coord.latitude, coord.longitude, RADIUS, center.latitude, center.longitude);
}
}
}
}
В моем журнале я получаю только ожидаемый результат, т. Е.показывает, какая широта и долгота находятся в пределах 100 метров, а какая широта и долгота находятся в пределах 100 метров, но в моем табличном представлении отображаются все широты и долготы, но мне нужно показать только широту и долготу, которые находятся в пределах 100метров, где я делаю ошибку.Заранее спасибо.