Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 3rd, 2012  |  syntax: None  |  size: 4.28 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to send the data to the table view depending on the condition
  2. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  3.     // Return the number of sections.
  4.     return 1;
  5. }
  6.  
  7.  
  8. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  9.     // Return the number of rows in the section.
  10.     return [dataArray count];
  11. }
  12.  
  13.  
  14. // Customize the appearance of table view cells.
  15. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  16.  
  17.     static NSString *CellIdentifier = @"Cell";
  18.  
  19.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  20.     if (cell == nil) {
  21.         cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
  22.     }
  23.  
  24.     Person *temp = (Person *)[self.persons objectAtIndex:indexPath.row];
  25.     cell.textLabel.text = temp.strName;
  26.  
  27.     // Configure the cell...
  28.  
  29.     return cell;
  30. }
  31.  
  32.  
  33.  
  34. - (void) readDataFromDatabase{
  35.  
  36.     sqlite3 *database;
  37.     persons = [[NSMutableArray alloc]init];
  38.  
  39.     if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK){
  40.  
  41.         const char *sqlStatement = "select * from sdata";
  42.         sqlite3_stmt *compiledStatement;
  43.         if (sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK){
  44.  
  45.             while (sqlite3_step(compiledStatement) == SQLITE_ROW) {
  46.  
  47.                 pID = sqlite3_column_int(compiledStatement, 0);
  48.                 //                NSLog(@" Id : %d",pID);
  49.                 pName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
  50.                 NSLog(@" Name : %@",pName);
  51.                 pAdd = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
  52.                 NSLog(@" Address : %@",pAdd);
  53.                 pPh = sqlite3_column_int(compiledStatement, 3);
  54.                 NSLog(@" PhoneNo : %d",pPh);
  55.                 pCp = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)];
  56.                 NSLog(@" ContactPerson : %@",pCp);
  57.                 pLat = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)];
  58.                 NSLog(@" Latitude : %@",pLat);
  59.                 pLong = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)];
  60.                 NSLog(@" Longitude : %@",pLong);
  61.  
  62.  
  63.  
  64.                 Person *temp = [[Person alloc]initWithID:pID name:pName address:pAdd phone:pPh contactperson:pCp fLat:pLat fLong:pLong];
  65.                 [persons addObject:temp];
  66.                 [temp release];
  67.  
  68.             }
  69.  
  70.         }
  71.         sqlite3_finalize(compiledStatement);
  72.     }
  73.     sqlite3_close(database);
  74. }
  75.  
  76.  
  77.  
  78. - (void)startTest
  79. {
  80.     for(int j=0;j<[persons count];j++){
  81.  
  82.         Person *arr = [persons objectAtIndex:j];
  83.  
  84.  
  85.         NSString *s = [[NSString alloc]initWithFormat:@"%@ %@ %@",arr.fLat,arr.fLong,arr.strName] ;
  86.        // NSLog(@" data in array : %@", s);
  87.  
  88.  
  89. #define COORDS_COUNT 1
  90. #define RADIUS       100.0f
  91.  
  92.     CLLocationCoordinate2D coords[COORDS_COUNT] = {
  93.         CLLocationCoordinate2DMake([arr.fLat floatValue], [arr.fLong floatValue ]),
  94.  
  95.  
  96.     };
  97.  
  98.     CLLocationCoordinate2D center = CLLocationCoordinate2DMake([lat floatValue], [longt floatValue]);
  99.     CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:center radius:RADIUS identifier:@"Banashankari"];
  100.  
  101.  
  102.  
  103.     for (int i = 0; i < COORDS_COUNT; i++)
  104.     {
  105.         CLLocationCoordinate2D coord = coords[i];
  106.  
  107.         NSString *coordString = [NSString stringWithFormat:@"%f,%f",coord.latitude, coord.longitude];
  108.         [dataArray addObject:coordString];
  109.  
  110.         if ([region containsCoordinate:coord])
  111.         {
  112.             NSLog(@"location %f, %f is within %.0f meters of coord %f, %f", coord.latitude, coord.longitude, RADIUS, center.latitude, center.longitude);
  113.             [resultArray addObject:coordString];
  114.             NSLog(@"data within 100 meters %@",resultArray);
  115.         }
  116.         else
  117.         {
  118.             NSLog(@"location %f, %f is not within %.0f meters of coord %f, %f", coord.latitude, coord.longitude, RADIUS, center.latitude, center.longitude);    
  119.  
  120.         }
  121.     }
  122.  
  123. }
  124. }
  125.        
  126. Person *temp = (Person *)[self.persons objectAtIndex:indexPath.row];
  127. cell.textLabel.text = temp.strName;
  128.        
  129. cell.textLabel.text = [dataarray objectAtIndex:indexPath.row];