Skip to content

Commit

Permalink
Correct classifiers, add place listings
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Fitzsimmons committed Jan 6, 2011
1 parent 864b95d commit ef60419
Show file tree
Hide file tree
Showing 7 changed files with 966 additions and 89 deletions.
8 changes: 4 additions & 4 deletions Classes/ContextViewController.h
Expand Up @@ -44,10 +44,10 @@
NSArray *contextData;
}

@property (nonatomic,retain) IBOutlet CLController *locationController;
@property (nonatomic,retain) IBOutlet SGController *simpleGeoController;
@property (nonatomic,retain) IBOutlet MKMapView *mapView;
@property (nonatomic,retain) IBOutlet UITableView *tableView;
@property (nonatomic,assign) IBOutlet CLController *locationController;
@property (nonatomic,assign) IBOutlet SGController *simpleGeoController;
@property (nonatomic,assign) IBOutlet MKMapView *mapView;
@property (nonatomic,assign) IBOutlet UITableView *tableView;
@property (nonatomic,assign) IBOutlet UITableViewCell *tvCell;

@property (nonatomic,retain) NSArray *contextData;
Expand Down
22 changes: 17 additions & 5 deletions Classes/ContextViewController.m
Expand Up @@ -55,6 +55,12 @@ - (void)viewDidAppear:(BOOL)animated
[self.mapView setRegion:region];
}

- (void)dealloc
{
[contextData release];
[super dealloc];
}

#pragma mark SimpleGeoDelegate methods

- (void)requestDidFail:(ASIHTTPRequest *)request
Expand All @@ -64,7 +70,7 @@ - (void)requestDidFail:(ASIHTTPRequest *)request

- (void)requestDidFinish:(ASIHTTPRequest *)request
{
NSLog(@"Request finished: %@", [request responseString]);
// NSLog(@"Request finished: %@", [request responseString]);
}

- (void)didLoadContext:(NSDictionary *)context
Expand Down Expand Up @@ -107,11 +113,17 @@ - (UITableViewCell *)tableView:(UITableView *)aTableView

NSDictionary *row = [contextData objectAtIndex:indexPath.row];
NSString *name = [row objectForKey:@"name"];
NSString *category = [row objectForKey:@"category"];
NSString *category = @"";

if ([[row objectForKey:@"classifiers"] count] > 0) {
NSDictionary *classifiers = [[row objectForKey:@"classifiers"] objectAtIndex:0];

category = [classifiers objectForKey:@"category"];

NSString *subcategory = (NSString *)[row objectForKey:@"subcategory"];
if (subcategory && ! [subcategory isEqual:@""]) {
category = [NSString stringWithFormat:@"%@%@", category, subcategory];
NSString *subcategory = (NSString *)[classifiers objectForKey:@"subcategory"];
if (subcategory && ! [subcategory isEqual:@""]) {
category = [NSString stringWithFormat:@"%@%@", category, subcategory];
}
}

UILabel *label;
Expand Down
17 changes: 16 additions & 1 deletion Classes/PlacesListViewController.h
Expand Up @@ -28,10 +28,25 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import "CLController.h"
#import "SGController.h"

@interface PlacesListViewController : UIViewController

@interface PlacesListViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
CLController *locationController;
SGController *simpleGeoController;
UITableView *tableView;
UITableViewCell *tvCell;

SGFeatureCollection *placeData;
}

@property (nonatomic,assign) IBOutlet CLController *locationController;
@property (nonatomic,assign) IBOutlet SGController *simpleGeoController;
@property (nonatomic,assign) IBOutlet UITableView *tableView;
@property (nonatomic,assign) IBOutlet UITableViewCell *tvCell;

@property (nonatomic,retain) SGFeatureCollection *placeData;

@end
115 changes: 115 additions & 0 deletions Classes/PlacesListViewController.m
Expand Up @@ -29,8 +29,123 @@
//

#import "PlacesListViewController.h"
#import "SimpleGeo+Places.h"


@implementation PlacesListViewController

@synthesize locationController;
@synthesize simpleGeoController;
@synthesize tableView;
@synthesize tvCell;
@synthesize placeData;

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

CLLocationCoordinate2D lastLocation = [[self.locationController lastLocation] coordinate];

[self.simpleGeoController setDelegate:self];
[self.simpleGeoController.client getPlacesNear:[SGPoint pointWithLatitude:lastLocation.latitude
longitude:lastLocation.longitude]];
}

- (void)dealloc
{
[placeData release];
[super dealloc];
}

#pragma mark SimpleGeoDelegate methods

- (void)requestDidFail:(ASIHTTPRequest *)request
{
NSLog(@"Request failed: %@: %i", [request responseStatusMessage], [request responseStatusCode]);
}

- (void)requestDidFinish:(ASIHTTPRequest *)request
{
// NSLog(@"Request finished: %@", [request responseString]);
}

- (void)didLoadPlaces:(SGFeatureCollection *)places
near:(SGPoint *)point
matching:(NSString *)query
inCategory:(NSString *)category
{
self.placeData = places;

[tableView reloadData];
}

#pragma mark UITableViewDataSource methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)aTableView
numberOfRowsInSection:(NSInteger)section
{
if (placeData) {
return [self.placeData count];
}

return 0;
}

- (UITableViewCell *)tableView:(UITableView *)aTableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *PlacesIdentifier = @"PlacesTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlacesIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"PlacesTVCell"
owner:self
options:nil];
cell = tvCell;
self.tvCell = nil;
}

SGFeature *place = [[self.placeData features] objectAtIndex:indexPath.row];
NSString *name = [[place properties] objectForKey:@"name"];
NSString *category = @"";

if ([[[place properties] objectForKey:@"classifiers"] count] > 0) {
NSDictionary *classifiers = [[[place properties] objectForKey:@"classifiers"] objectAtIndex:0];

category = [classifiers objectForKey:@"category"];

NSString *subcategory = (NSString *)[classifiers objectForKey:@"subcategory"];
if (subcategory && ! [subcategory isEqual:@""]) {
category = [NSString stringWithFormat:@"%@ : %@", category, subcategory];
}
}

// TODO add distance to category

UILabel *label;
label = (UILabel *)[cell viewWithTag:1];
label.text = category;

label = (UILabel *)[cell viewWithTag:2];
label.text = name;

return cell;
}

#pragma mark UITableViewDelegate methods

- (CGFloat)tableView:(UITableView *)aTableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == [self.placeData count] - 1) {
return 73.0;
}

return 70.0;
}

@end

0 comments on commit ef60419

Please sign in to comment.