From 022a72897f57da9e55d0fb90b967d16e3c7af1d7 Mon Sep 17 00:00:00 2001 From: charles Date: Sat, 20 Feb 2016 16:01:54 -0500 Subject: [PATCH 1/3] commit --- .../FixaDaApp/Base.lproj/Main.storyboard | 28 +++--- FixaDaApp/FixaDaApp/FoursquareAPIManager.m | 25 ++++-- FixaDaApp/FixaDaApp/ViewController.m | 86 +++++++++++++------ 3 files changed, 92 insertions(+), 47 deletions(-) diff --git a/FixaDaApp/FixaDaApp/Base.lproj/Main.storyboard b/FixaDaApp/FixaDaApp/Base.lproj/Main.storyboard index ed571b5..2d9c0fb 100644 --- a/FixaDaApp/FixaDaApp/Base.lproj/Main.storyboard +++ b/FixaDaApp/FixaDaApp/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -18,25 +18,22 @@ - - - - + - + - + @@ -44,16 +41,19 @@ + + + - - + + + - - - + + diff --git a/FixaDaApp/FixaDaApp/FoursquareAPIManager.m b/FixaDaApp/FixaDaApp/FoursquareAPIManager.m index b0ee3ac..fe36e36 100644 --- a/FixaDaApp/FixaDaApp/FoursquareAPIManager.m +++ b/FixaDaApp/FixaDaApp/FoursquareAPIManager.m @@ -14,7 +14,9 @@ @implementation FoursquareAPIManager -/** +// 40.741836, -74.004397 + +/* https://api.foursquare.com/v2/venues/search?client_id=IN4V05KYYXLPDXGIHMCDSPVIAG30BTOG4NC3AEAYFYIQZID0%20&client_secret=CD31L2IZKSYQ1AAGTHQQEF2GHXJLI43CXYV1KVCEEUQZQ2G4%20&v=20130815%20&ll=40.741836,-74.004397%20&query=venues%20&limit=50 https://api.foursquare.com/v2/venues/search ?client_id=CLIENT_ID @@ -23,12 +25,13 @@ @implementation FoursquareAPIManager &ll=40.7,-74 &query=sushi -**/ + */ + (void)findSomething:(NSString *)query atLocation:(CLLocation *)location completion:(void(^)(NSArray *data))completion { + query = [query stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]; 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 +41,17 @@ + (void)findSomething:(NSString *)query parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) - { - - } failure:^(NSURLSessionTask *operation, NSError *error) - { - NSLog(@"Error: %@", error); - }]; - + { + NSDictionary *response = [responseObject objectForKey:@"response"]; + NSArray *venues = [response objectForKey:@"venues"]; + completion(venues); + NSLog(@"%@", venues); + + } failure:^(NSURLSessionTask *operation, NSError *error) + { + NSLog(@"Error: %@", error); + }]; + } @end diff --git a/FixaDaApp/FixaDaApp/ViewController.m b/FixaDaApp/FixaDaApp/ViewController.m index f938005..27c7142 100644 --- a/FixaDaApp/FixaDaApp/ViewController.m +++ b/FixaDaApp/FixaDaApp/ViewController.m @@ -5,16 +5,18 @@ // Created by Michael Kavouras on 2/14/16. // Copyright © 2016 Michael Kavouras. All rights reserved. // +#import +#import #import "ViewController.h" -#import #import "FoursquareAPIManager.h" @interface ViewController () < UITableViewDataSource, UITableViewDelegate, -MKMapViewDelegate +MKMapViewDelegate, +CLLocationManagerDelegate > @property (weak, nonatomic) IBOutlet MKMapView *mapView; @@ -22,6 +24,9 @@ @interface ViewController () @property (nonatomic) CLLocationManager *locationManager; +@property (nonatomic) CLLocation *location; +@property (nonatomic) BOOL hasUserLocation; + @property (nonatomic, assign) BOOL foundPlaces; @property (nonatomic) NSArray *venues; @@ -30,23 +35,25 @@ @interface ViewController () @implementation ViewController -- (void)viewDidLoad { +- (void)viewDidLoad +{ [super viewDidLoad]; + self.locationManager = [[CLLocationManager alloc] init]; + self.tableView.delegate = self; self.tableView.dataSource = self; - self.mapView.delegate = self; - - self.locationManager = [[CLLocationManager alloc] init]; + [self setCurrentLocation]; + [self startMaps]; } -- (void)viewDidAppear:(BOOL)animated +- (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; + [self.locationManager requestWhenInUseAuthorization]; } - # pragma mark - Table view datasource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView @@ -56,12 +63,12 @@ - (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"]; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BeepBoopCellIdentifier" forIndexPath:indexPath]; NSDictionary *venue = self.venues[indexPath.row]; NSString *name = venue[@"name"]; @@ -84,7 +91,7 @@ - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)use - (void)zoomToLocation:(CLLocation *)location { - MKCoordinateSpan span = MKCoordinateSpanMake(0.05f,0.05f); + MKCoordinateSpan span = MKCoordinateSpanMake(0.005f,0.005f); CLLocationCoordinate2D coordinate = location.coordinate; MKCoordinateRegion region = {coordinate, span}; MKCoordinateRegion regionThatFits = [self.mapView regionThatFits:region]; @@ -93,22 +100,20 @@ - (void)zoomToLocation:(CLLocation *)location - (void)fetchVenuesAtLocation:(CLLocation *)location { - __weak typeof(self) weakSelf = self; - [FoursquareAPIManager findSomething:@"music" - atLocation:location - completion:^(NSArray *data){ - - weakSelf.venues = data; - [weakSelf.tableView reloadData]; - [weakSelf showPins]; - - }]; + __weak typeof(self) weakSelf = self; + [FoursquareAPIManager findSomething:@"venues" + atLocation:location + completion:^(NSArray *data){ + + weakSelf.venues = data; + [weakSelf.tableView reloadData]; + [weakSelf showPinsForVenues]; + + }]; } -- (void)showPins +- (void)showPinsForVenues { - [self.mapView removeAnnotations:self.mapView.annotations]; - for (NSDictionary *venue in self.venues) { double lat = [venue[@"location"][@"lat"] doubleValue]; double lng = [venue[@"location"][@"lng"] doubleValue]; @@ -119,4 +124,37 @@ - (void)showPins } } +# pragma mark - Charles' Methods + +- (void)setCurrentLocation +{ + + if (self.locationManager == nil){ + self.locationManager = [[CLLocationManager alloc]init]; + } + + self.locationManager.distanceFilter = kCLDistanceFilterNone; + self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; +} + +- (void)startMaps +{ + self.mapView.delegate = self; + self.hasUserLocation = YES; + self.mapView.showsUserLocation = YES; +} + +- (void)showPinsForPlaces +{ + [self.mapView removeAnnotations:self.mapView.annotations]; + for (NSDictionary *venueResults in self.venues) { + double lat = [venueResults[@"location"][@"lat"] doubleValue]; + double lng = [venueResults[@"location"][@"lng"] doubleValue]; + + MKPointAnnotation *pin = [[MKPointAnnotation alloc] init]; + pin.coordinate = CLLocationCoordinate2DMake(lat, lng); + [self.mapView addAnnotation:pin]; + } +} + @end From f0c4a4f27c14be1e0b6556137e5d92257fae6ae4 Mon Sep 17 00:00:00 2001 From: charles Date: Sat, 20 Feb 2016 16:09:23 -0500 Subject: [PATCH 2/3] 2nd commit --- FixaDaApp/FixaDaApp/ViewController.m | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/FixaDaApp/FixaDaApp/ViewController.m b/FixaDaApp/FixaDaApp/ViewController.m index 27c7142..aefb744 100644 --- a/FixaDaApp/FixaDaApp/ViewController.m +++ b/FixaDaApp/FixaDaApp/ViewController.m @@ -44,7 +44,7 @@ - (void)viewDidLoad self.tableView.delegate = self; self.tableView.dataSource = self; - [self setCurrentLocation]; + // [self setCurrentLocation]; [self startMaps]; } @@ -91,7 +91,7 @@ - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)use - (void)zoomToLocation:(CLLocation *)location { - MKCoordinateSpan span = MKCoordinateSpanMake(0.005f,0.005f); + MKCoordinateSpan span = MKCoordinateSpanMake(0.03f,0.03f); CLLocationCoordinate2D coordinate = location.coordinate; MKCoordinateRegion region = {coordinate, span}; MKCoordinateRegion regionThatFits = [self.mapView regionThatFits:region]; @@ -101,7 +101,7 @@ - (void)zoomToLocation:(CLLocation *)location - (void)fetchVenuesAtLocation:(CLLocation *)location { __weak typeof(self) weakSelf = self; - [FoursquareAPIManager findSomething:@"venues" + [FoursquareAPIManager findSomething:@"music" atLocation:location completion:^(NSArray *data){ @@ -126,27 +126,16 @@ - (void)showPinsForVenues # pragma mark - Charles' Methods -- (void)setCurrentLocation -{ - - if (self.locationManager == nil){ - self.locationManager = [[CLLocationManager alloc]init]; - } - - self.locationManager.distanceFilter = kCLDistanceFilterNone; - self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; -} - - (void)startMaps { - self.mapView.delegate = self; - self.hasUserLocation = YES; self.mapView.showsUserLocation = YES; + self.mapView.delegate = self; } - (void)showPinsForPlaces { [self.mapView removeAnnotations:self.mapView.annotations]; + for (NSDictionary *venueResults in self.venues) { double lat = [venueResults[@"location"][@"lat"] doubleValue]; double lng = [venueResults[@"location"][@"lng"] doubleValue]; @@ -156,5 +145,16 @@ - (void)showPinsForPlaces [self.mapView addAnnotation:pin]; } } +// don't need this +//- (void)setCurrentLocation +//{ +// +// if (self.locationManager == nil){ +// self.locationManager = [[CLLocationManager alloc]init]; +// } +// +// self.locationManager.distanceFilter = kCLDistanceFilterNone; +// self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; +//} @end From f22472dfd9832e3d596603e55db0343d3d7b3beb Mon Sep 17 00:00:00 2001 From: charles Date: Sat, 20 Feb 2016 16:10:26 -0500 Subject: [PATCH 3/3] last commit --- FixaDaApp/FixaDaApp/FoursquareAPIManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FixaDaApp/FixaDaApp/FoursquareAPIManager.m b/FixaDaApp/FixaDaApp/FoursquareAPIManager.m index fe36e36..a0f3b5b 100644 --- a/FixaDaApp/FixaDaApp/FoursquareAPIManager.m +++ b/FixaDaApp/FixaDaApp/FoursquareAPIManager.m @@ -14,7 +14,7 @@ @implementation FoursquareAPIManager -// 40.741836, -74.004397 +// 40.741836, -74.004397 Spotify /* https://api.foursquare.com/v2/venues/search?client_id=IN4V05KYYXLPDXGIHMCDSPVIAG30BTOG4NC3AEAYFYIQZID0%20&client_secret=CD31L2IZKSYQ1AAGTHQQEF2GHXJLI43CXYV1KVCEEUQZQ2G4%20&v=20130815%20&ll=40.741836,-74.004397%20&query=venues%20&limit=50