Permalink
Browse files

WIP - now full list of files

  • Loading branch information...
1 parent 5d626b9 commit b519f25cb91a38fa73aa73eaabb167aadb2a7c80 @ruslansv committed Aug 15, 2012

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -8,6 +8,6 @@
#import <UIKit/UIKit.h>
-@interface BYRFirstViewController : UIViewController
+@interface BYRHomeViewController : UIViewController
@end
@@ -6,13 +6,13 @@
// Copyright (c) 2012 Ruslan Belkin. All rights reserved.
//
-#import "BYRFirstViewController.h"
+#import "BYRHomeViewController.h"
-@interface BYRFirstViewController ()
+@interface BYRHomeViewController ()
@end
-@implementation BYRFirstViewController
+@implementation BYRHomeViewController
- (void)viewDidLoad
{
@@ -7,13 +7,26 @@
//
#import "BYRMapViewController.h"
+#import <MapKit/MapKit.h>
+
+#import "BYRPinAnnotation.h"
@interface BYRMapViewController ()
+@property (weak, nonatomic) IBOutlet MKMapView *mapView;
+@property CLLocationManager* locationMgr;
+
+@property BOOL mapAdjusted;
+
@end
@implementation BYRMapViewController
+@synthesize mapView;
+@synthesize locationMgr;
+
+@synthesize mapAdjusted;
+
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
@@ -23,15 +36,35 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
return self;
}
+#define BYRCoordinates CLLocationCoordinate2DMake(37.2871892,-121.9468954)
+
- (void)viewDidLoad
{
[super viewDidLoad];
+
// Do any additional setup after loading the view.
+
+ self.mapAdjusted = NO;
+
+ CLLocationCoordinate2D byrLocation = BYRCoordinates;
+
+ BYRPinAnnotation* pa = [[BYRPinAnnotation alloc] initWithCoordinates:byrLocation withTitle:@"BYR" andSubTitle:@"of Belgium"];
+
+ [self.mapView addAnnotation:pa];
+
+ [self.mapView.userLocation addObserver:self
+ forKeyPath:@"location"
+ options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
+ context:NULL];
}
- (void)viewDidUnload
{
+ [self.mapView.userLocation removeObserver:self forKeyPath:@"location"];
+
+ [self setMapView:nil];
[super viewDidUnload];
+
// Release any retained subviews of the main view.
}
@@ -40,4 +73,72 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
+#pragma mark CLLocationManagerDelegate
+
+-(void)centerToBYR
+{
+ MKUserLocation* myLocation = self.mapView.userLocation;
+ if(myLocation)
+ {
+ CLLocationCoordinate2D myCoordinates = myLocation.coordinate;
+
+ CLLocationDegrees laDelta = fabs(myCoordinates.latitude - BYRCoordinates.latitude) * 2.1;
+ CLLocationDegrees loDelta = fabs(myCoordinates.longitude - BYRCoordinates.longitude) * 2.1;
+
+ MKCoordinateRegion region;
+
+ region.center.latitude = BYRCoordinates.latitude;
+ region.center.longitude = BYRCoordinates.longitude;
+
+ region.span.latitudeDelta = laDelta;
+ region.span.longitudeDelta = loDelta;
+
+ region = [self.mapView regionThatFits:region];
+ [self.mapView setRegion:region animated:YES];
+
+ self.mapAdjusted = YES;
+ }
+}
+
+-(void)centerToMyLocaion
+{
+ MKUserLocation* myLocation = self.mapView.userLocation;
+ if(myLocation)
+ {
+ CLLocationCoordinate2D myCoordinates = myLocation.coordinate;
+
+ CLLocationDegrees laDelta = fabs(myCoordinates.latitude - BYRCoordinates.latitude) * 2.1;
+ CLLocationDegrees loDelta = fabs(myCoordinates.longitude - BYRCoordinates.longitude) * 2.1;
+
+ MKCoordinateRegion region;
+
+ region.center.latitude = myCoordinates.latitude;
+ region.center.longitude = myCoordinates.longitude;
+
+ region.span.latitudeDelta = laDelta;
+ region.span.longitudeDelta = loDelta;
+
+ region = [self.mapView regionThatFits:region];
+ [self.mapView setRegion:region animated:YES];
+
+ self.mapAdjusted = YES;
+ }
+}
+
+-(void)observeValueForKeyPath:(NSString *)keyPath
+ ofObject:(id)object
+ change:(NSDictionary *)change
+ context:(void *)context
+{
+ if(!self.mapAdjusted)
+ {
+ [self centerToBYR];
+ }
+}
+
+- (IBAction)centerLocationPressed:(id)sender
+{
+ [self centerToMyLocaion];
+}
+
@end
@@ -7,7 +7,16 @@
//
#import <Foundation/Foundation.h>
+#import <MapKit/MapKit.h>
-@interface BYRPinAnnotation : NSObject
+@interface BYRPinAnnotation : NSObject<MKAnnotation>
+
+@property (nonatomic,readonly) CLLocationCoordinate2D coordinate;
+@property (nonatomic,copy,readonly) NSString* title;
+@property (nonatomic,copy,readonly) NSString* subtitle;
+
+-(id) initWithCoordinates:(CLLocationCoordinate2D)pCoordinates
+ withTitle:(NSString*)pTitle
+ andSubTitle:(NSString*)pSubTitle;
@end
@@ -10,4 +10,20 @@
@implementation BYRPinAnnotation
+@synthesize coordinate, title, subtitle;
+
+-(id) initWithCoordinates:(CLLocationCoordinate2D)pCoordinates
+ withTitle:(NSString*)pTitle
+ andSubTitle:(NSString*)pSubTitle
+{
+ self = [super init];
+ if(self)
+ {
+ coordinate = pCoordinates;
+ title = pTitle;
+ subtitle = pSubTitle;
+ }
+ return self;
+}
+
@end
@@ -8,6 +8,6 @@
#import <UIKit/UIKit.h>
-@interface BYRSecondViewController : UIViewController
+@interface BYRRewardsViewController : UIViewController
@end
@@ -6,13 +6,13 @@
// Copyright (c) 2012 Ruslan Belkin. All rights reserved.
//
-#import "BYRSecondViewController.h"
+#import "BYRRewardsViewController.h"
-@interface BYRSecondViewController ()
+@interface BYRRewardsViewController ()
@end
-@implementation BYRSecondViewController
+@implementation BYRRewardsViewController
- (void)viewDidLoad
{
Oops, something went wrong.

0 comments on commit b519f25

Please sign in to comment.