diff --git a/FixaDaApp/FixaDaApp.xcodeproj/project.pbxproj b/FixaDaApp/FixaDaApp.xcodeproj/project.pbxproj index d7126a8..fc163bd 100644 --- a/FixaDaApp/FixaDaApp.xcodeproj/project.pbxproj +++ b/FixaDaApp/FixaDaApp.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 4D31B3791C792A6700171150 /* VenueObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D31B3781C792A6700171150 /* VenueObject.m */; }; 79510F25E25C142657CE2DC4 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5C1C5BEFC8D1D1F43B84295A /* libPods.a */; }; 8D4F05B61C710A8E003B3131 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D4F05B51C710A8E003B3131 /* main.m */; }; 8D4F05B91C710A8E003B3131 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D4F05B81C710A8E003B3131 /* AppDelegate.m */; }; @@ -20,6 +21,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 4D31B3771C792A6700171150 /* VenueObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VenueObject.h; sourceTree = ""; }; + 4D31B3781C792A6700171150 /* VenueObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VenueObject.m; sourceTree = ""; }; 51DA72322BD0057FB2DF45ED /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 5C1C5BEFC8D1D1F43B84295A /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 8D4F05B11C710A8E003B3131 /* FixaDaApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FixaDaApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -91,6 +94,8 @@ 8D4F05BB1C710A8E003B3131 /* ViewController.m */, 8DB9ED8E1C722B12003A03E0 /* FoursquareAPIManager.h */, 8DB9ED8F1C722B13003A03E0 /* FoursquareAPIManager.m */, + 4D31B3771C792A6700171150 /* VenueObject.h */, + 4D31B3781C792A6700171150 /* VenueObject.m */, 8D4F05BD1C710A8E003B3131 /* Main.storyboard */, 8D4F05C01C710A8E003B3131 /* Assets.xcassets */, 8D4F05C21C710A8E003B3131 /* LaunchScreen.storyboard */, @@ -241,6 +246,7 @@ 8D4F05B91C710A8E003B3131 /* AppDelegate.m in Sources */, 8D4F05B61C710A8E003B3131 /* main.m in Sources */, 8DB9ED901C722B13003A03E0 /* FoursquareAPIManager.m in Sources */, + 4D31B3791C792A6700171150 /* VenueObject.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FixaDaApp/FixaDaApp/Base.lproj/Main.storyboard b/FixaDaApp/FixaDaApp/Base.lproj/Main.storyboard index ed571b5..f434559 100644 --- a/FixaDaApp/FixaDaApp/Base.lproj/Main.storyboard +++ b/FixaDaApp/FixaDaApp/Base.lproj/Main.storyboard @@ -19,13 +19,13 @@ - + - + - + @@ -48,7 +48,7 @@ - + diff --git a/FixaDaApp/FixaDaApp/FoursquareAPIManager.h b/FixaDaApp/FixaDaApp/FoursquareAPIManager.h index f9ef616..613515d 100644 --- a/FixaDaApp/FixaDaApp/FoursquareAPIManager.h +++ b/FixaDaApp/FixaDaApp/FoursquareAPIManager.h @@ -13,6 +13,6 @@ + (void)findSomething:(NSString *)query atLocation:(CLLocation *)location - completion:(void(^)(NSArray *data))completion; + completion:(void(^)(NSMutableArray *data))completion; @end diff --git a/FixaDaApp/FixaDaApp/FoursquareAPIManager.m b/FixaDaApp/FixaDaApp/FoursquareAPIManager.m index b0ee3ac..859e5aa 100644 --- a/FixaDaApp/FixaDaApp/FoursquareAPIManager.m +++ b/FixaDaApp/FixaDaApp/FoursquareAPIManager.m @@ -8,10 +8,15 @@ #import "FoursquareAPIManager.h" #import +#import "VenueObject.h" #define kFoursquareAPIClientID @"GWKJBVWFYBJQ02T3TRBB4VBL24AIO4TCMJCGIQ5ADKVKJXGP" #define kFoursquareAPIClientSecret @"2WMEZCDQNKNB5XAE5F4BY1VHBK1HITYRU1JEVCOAD2QRLXDJ" +@interface FoursquareAPIManager () + +@end + @implementation FoursquareAPIManager /** @@ -23,12 +28,14 @@ @implementation FoursquareAPIManager &ll=40.7,-74 &query=sushi -**/ + **/ + (void)findSomething:(NSString *)query atLocation:(CLLocation *)location - completion:(void(^)(NSArray *data))completion + completion:(void(^)(NSMutableArray *data))completion { + NSMutableArray *locations = [[NSMutableArray alloc] init]; // alloc init array + NSString *baseURL = @"https://api.foursquare.com/v2/venues/search"; NSString *url = [NSString stringWithFormat:@"%@?client_id=%@&client_secret=%@&v=20160215&ll=%f,%f&query=%@", baseURL, kFoursquareAPIClientID, kFoursquareAPIClientSecret, location.coordinate.latitude, location.coordinate.longitude, query]; @@ -38,13 +45,37 @@ + (void)findSomething:(NSString *)query parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) - { - - } failure:^(NSURLSessionTask *operation, NSError *error) - { - NSLog(@"Error: %@", error); - }]; - + { + + if (responseObject != nil) { + + NSArray *venuesMy = [[responseObject objectForKey:@"response"] objectForKey:@"venues"]; + + for (NSDictionary *venue in venuesMy) { + + NSString *venueName = [venue objectForKey:@"name"]; // pull info from dictionary + NSString *lat = [[venue objectForKey:@"location"]objectForKey:@"lat"]; + NSString *lng = [[venue objectForKey:@"location"]objectForKey:@"lng"]; + + double latDbl = lat.doubleValue; // convert to doubles + double lngDbl = lng.doubleValue; + + VenueObject *venue = [[VenueObject alloc] init]; // initialize storage object + + venue.name = venueName; // save in object + venue.lat = latDbl; + venue.lng = lngDbl; + + [locations addObject:venue]; // add to object + } + completion(locations); + } + + } failure:^(NSURLSessionTask *operation, NSError *error) + { + NSLog(@"Error: %@", error); + }]; + } @end diff --git a/FixaDaApp/FixaDaApp/Info.plist b/FixaDaApp/FixaDaApp/Info.plist index cf463a3..776c719 100644 --- a/FixaDaApp/FixaDaApp/Info.plist +++ b/FixaDaApp/FixaDaApp/Info.plist @@ -3,7 +3,7 @@ NSLocationWhenInUseUsageDescription - Show you the places! + Hi, please accept so that we can show you the places! CFBundleDevelopmentRegion en CFBundleExecutable diff --git a/FixaDaApp/FixaDaApp/VenueObject.h b/FixaDaApp/FixaDaApp/VenueObject.h new file mode 100644 index 0000000..c004394 --- /dev/null +++ b/FixaDaApp/FixaDaApp/VenueObject.h @@ -0,0 +1,17 @@ +// +// VenueObject.h +// FixaDaApp +// +// Created by Shena Yoshida on 2/20/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import + +@interface VenueObject : NSObject + +@property (nonatomic) NSString *name; +@property (nonatomic) double lat; +@property (nonatomic) double lng; + +@end diff --git a/FixaDaApp/FixaDaApp/VenueObject.m b/FixaDaApp/FixaDaApp/VenueObject.m new file mode 100644 index 0000000..598da64 --- /dev/null +++ b/FixaDaApp/FixaDaApp/VenueObject.m @@ -0,0 +1,13 @@ +// +// VenueObject.m +// FixaDaApp +// +// Created by Shena Yoshida on 2/20/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "VenueObject.h" + +@implementation VenueObject + +@end diff --git a/FixaDaApp/FixaDaApp/ViewController.m b/FixaDaApp/FixaDaApp/ViewController.m index f938005..c5281b1 100644 --- a/FixaDaApp/FixaDaApp/ViewController.m +++ b/FixaDaApp/FixaDaApp/ViewController.m @@ -8,7 +8,9 @@ #import "ViewController.h" #import +#import #import "FoursquareAPIManager.h" +#import "VenueObject.h" @interface ViewController () < @@ -19,12 +21,10 @@ @interface ViewController () @property (weak, nonatomic) IBOutlet MKMapView *mapView; @property (weak, nonatomic) IBOutlet UITableView *tableView; - @property (nonatomic) CLLocationManager *locationManager; - @property (nonatomic, assign) BOOL foundPlaces; -@property (nonatomic) NSArray *venues; +@property (nonatomic) NSMutableArray *venues; @end @@ -33,17 +33,21 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; + self.mapView.showsUserLocation = YES; + self.locationManager = [[CLLocationManager alloc] init]; + self.tableView.delegate = self; self.tableView.dataSource = self; self.mapView.delegate = self; - self.locationManager = [[CLLocationManager alloc] init]; + self.venues = [[NSMutableArray alloc] init]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; + [self.locationManager requestWhenInUseAuthorization]; } @@ -56,15 +60,15 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 0; + return self.venues.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BeepBoopCellIdentifier"]; - - NSDictionary *venue = self.venues[indexPath.row]; - NSString *name = venue[@"name"]; + + VenueObject *venue = self.venues[indexPath.row]; + NSString *name = venue.name; // this comes from the api call and object... cell.textLabel.text = name; return cell; @@ -96,7 +100,9 @@ - (void)fetchVenuesAtLocation:(CLLocation *)location __weak typeof(self) weakSelf = self; [FoursquareAPIManager findSomething:@"music" atLocation:location - completion:^(NSArray *data){ + completion:^(NSMutableArray *data){ + + self.venues = data; // pull data with the block! weakSelf.venues = data; [weakSelf.tableView reloadData]; @@ -109,14 +115,15 @@ - (void)showPins { [self.mapView removeAnnotations:self.mapView.annotations]; - for (NSDictionary *venue in self.venues) { - double lat = [venue[@"location"][@"lat"] doubleValue]; - double lng = [venue[@"location"][@"lng"] doubleValue]; - + for (VenueObject *venue in self.venues) { + double lat = venue.lat; + double lng = venue.lng; + MKPointAnnotation *point = [[MKPointAnnotation alloc] init]; point.coordinate = CLLocationCoordinate2DMake(lat, lng); [self.mapView addAnnotation:point]; } } + @end