Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions FixaDaApp/FixaDaApp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
Expand All @@ -18,42 +18,42 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<mapView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" mapType="standard" showsUserLocation="YES" translatesAutoresizingMaskIntoConstraints="NO" id="QhC-Y4-i8h">
<rect key="frame" x="0.0" y="0.0" width="600" height="100"/>
</mapView>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="BMq-V3-f2f">
<rect key="frame" x="0.0" y="100" width="600" height="500"/>
<rect key="frame" x="0.0" y="240" width="600" height="360"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="4Wd-lS-p0j" style="IBUITableViewCellStyleDefault" id="5cm-8d-a5a">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="BeepBoopCellIdentifier" textLabel="4Wd-lS-p0j" style="IBUITableViewCellStyleDefault" id="5cm-8d-a5a">
<rect key="frame" x="0.0" y="28" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="5cm-8d-a5a" id="cpW-0e-B2H">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="4Wd-lS-p0j">
<rect key="frame" x="15" y="0.0" width="570" height="43.5"/>
<rect key="frame" x="15" y="0.0" width="570" height="43"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
</tableView>
<mapView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" mapType="standard" showsUserLocation="YES" translatesAutoresizingMaskIntoConstraints="NO" id="QhC-Y4-i8h">
<rect key="frame" x="0.0" y="0.0" width="600" height="240"/>
</mapView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="BMq-V3-f2f" firstAttribute="top" secondItem="QhC-Y4-i8h" secondAttribute="bottom" id="829-uy-XA8"/>
<constraint firstItem="QhC-Y4-i8h" firstAttribute="height" secondItem="BMq-V3-f2f" secondAttribute="height" multiplier="0.2" id="DcL-ga-xdl"/>
<constraint firstAttribute="trailing" secondItem="QhC-Y4-i8h" secondAttribute="trailing" id="D7s-6g-vmG"/>
<constraint firstAttribute="trailing" secondItem="BMq-V3-f2f" secondAttribute="trailing" id="Ddx-sp-gAW"/>
<constraint firstItem="QhC-Y4-i8h" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="IEX-eg-bGb"/>
<constraint firstItem="BMq-V3-f2f" firstAttribute="top" secondItem="QhC-Y4-i8h" secondAttribute="bottom" id="KLd-eU-DEv"/>
<constraint firstItem="BMq-V3-f2f" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="PGd-F5-XwA"/>
<constraint firstItem="QhC-Y4-i8h" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="PS4-bX-CJK"/>
<constraint firstAttribute="trailing" secondItem="QhC-Y4-i8h" secondAttribute="trailing" id="mbZ-IW-xGJ"/>
<constraint firstItem="QhC-Y4-i8h" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="sq5-GT-TWp"/>
<constraint firstItem="QhC-Y4-i8h" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="dvT-An-Qv5"/>
<constraint firstItem="QhC-Y4-i8h" firstAttribute="height" secondItem="8bC-Xf-vdC" secondAttribute="height" multiplier="0.4" id="lgj-w9-Yif"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="BMq-V3-f2f" secondAttribute="bottom" id="vLg-lx-GXH"/>
</constraints>
</view>
Expand Down
25 changes: 16 additions & 9 deletions FixaDaApp/FixaDaApp/FoursquareAPIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

@implementation FoursquareAPIManager

/**
// 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

https://api.foursquare.com/v2/venues/search
?client_id=CLIENT_ID
Expand All @@ -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];

Expand All @@ -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
86 changes: 62 additions & 24 deletions FixaDaApp/FixaDaApp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
// Created by Michael Kavouras on 2/14/16.
// Copyright © 2016 Michael Kavouras. All rights reserved.
//
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

#import "ViewController.h"
#import <MapKit/MapKit.h>
#import "FoursquareAPIManager.h"

@interface ViewController ()
<
UITableViewDataSource,
UITableViewDelegate,
MKMapViewDelegate
MKMapViewDelegate,
CLLocationManagerDelegate
>

@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic) CLLocationManager *locationManager;

@property (nonatomic) CLLocation *location;
@property (nonatomic) BOOL hasUserLocation;

@property (nonatomic, assign) BOOL foundPlaces;

@property (nonatomic) NSArray *venues;
Expand All @@ -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
Expand All @@ -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"];
Expand All @@ -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.03f,0.03f);
CLLocationCoordinate2D coordinate = location.coordinate;
MKCoordinateRegion region = {coordinate, span};
MKCoordinateRegion regionThatFits = [self.mapView regionThatFits:region];
Expand All @@ -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:@"music"
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];
Expand All @@ -119,4 +124,37 @@ - (void)showPins
}
}

# pragma mark - Charles' Methods

- (void)startMaps
{
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];

MKPointAnnotation *pin = [[MKPointAnnotation alloc] init];
pin.coordinate = CLLocationCoordinate2DMake(lat, lng);
[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