Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add some comments, fix minor issue.

  • Loading branch information...
commit 65dc22573b5bbbfdbe1bf20bddbabf34d5b274e8 1 parent 36081b7
Tim Arnold authored
15 Routes/TAMapViewController.m
View
@@ -15,10 +15,20 @@ - (void)viewDidLoad {
_mapView.showsUserLocation = YES;
+ // Set up MKUserTrackingBarButtonItem
_trackingBBI = [[MKUserTrackingBarButtonItem alloc] initWithMapView:_mapView];
_toolbar.barStyle = UIBarStyleBlack;
_toolbar.translucent = YES;
+ // Note: we are using Core Location directly to get the user location updates.
+ // We could normally use MKMapView's user location update delegation but this does not work in
+ // the background. Plus we want "kCLLocationAccuracyBestForNavigation" which gives us a better accuracy.
+ //
+ // kCLLocationAccuracyBestForNavigation is the highest possible
+ // accuracy. Note that level of accuracy is intended
+ // for use in navigation applications that require precise position information at all times and
+ // are intended to be used only while the device is plugged in.
+ //
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
@@ -27,6 +37,7 @@ - (void)viewDidLoad {
#pragma mark - Class methods
+// Removes overlay and annotation pins from map
- (void)removeRouteFromMap {
if (nil != self.crumbs) {
[self.mapView removeOverlay:self.crumbs];
@@ -41,6 +52,7 @@ - (void)removeRouteFromMap {
}
}
+// Adds a red end pin annotation
- (void)addEndPinWithLocation:(CLLocation *)loc {
if (nil == self.endPin) {
self.endPin = [[TAMapPin alloc] initWithCoordinates:loc.coordinate
@@ -52,6 +64,7 @@ - (void)addEndPinWithLocation:(CLLocation *)loc {
[self.mapView addAnnotation:self.endPin];
}
+// Adds a green start pin annotation
- (void)addStartPinWithLocation:(CLLocation *)loc {
if (nil == self.startPin) {
self.startPin = [[TAMapPin alloc] initWithCoordinates:loc.coordinate
@@ -63,8 +76,8 @@ - (void)addStartPinWithLocation:(CLLocation *)loc {
[self.mapView addAnnotation:self.startPin];
}
+// Zooms map to a location
- (void)zoomMapToLocation:(CLLocationCoordinate2D)coord {
- // On the first location update only, zoom map to user location
MKCoordinateRegion region =
MKCoordinateRegionMakeWithDistance(coord, 2000, 2000);
[_mapView setRegion:region animated:YES];
12 Routes/TARecordViewController.m
View
@@ -60,6 +60,7 @@ -(BOOL)canBecomeFirstResponder {
return YES;
}
+// Handle a shake
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
[self removeRouteFromMap];
@@ -68,10 +69,12 @@ - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
#pragma mark - Private helper functions
+// Dismiss Routes View Controller
- (void)dismissRoutesVC:(id)sender {
[self dismissViewControllerAnimated:YES completion:^{ }];
}
+// Show Routes View Controller
- (void)showRoutes:(id)sender {
_routesVC = [[TARoutesViewController alloc] init];
@@ -90,9 +93,6 @@ - (void)updateOverlayWithLocation:(CLLocation *)loc {
//
self.crumbs = [[CrumbPath alloc] initWithCenterCoordinate:loc.coordinate];
[self.mapView addOverlay:self.crumbs];
-
- // On the first location update only, zoom map to user location
- [self zoomMapToLocation:loc.coordinate];
} else {
// This is a subsequent location update.
// If the crumbs MKOverlay model object determines that the current location has moved
@@ -118,6 +118,7 @@ - (void)updateOverlayWithLocation:(CLLocation *)loc {
}
}
+// When the user starts recording
- (void)startRecording {
[self removeRouteFromMap];
@@ -127,10 +128,11 @@ - (void)startRecording {
double delayInSeconds = 0.75;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
- self.mapView.userTrackingMode = MKUserTrackingModeFollow;
+ [self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
});
}
+// When the user stops recording
- (void)stopRecording {
[self addEndPinWithLocation:self.locationManager.location];
@@ -148,6 +150,7 @@ - (void)stopRecording {
#pragma mark - UIAlertViewDelegate
+// Alert View confirmation for saving or discarding a route.
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex != alertView.cancelButtonIndex) {
if (nil != _currentRoute) {
@@ -169,6 +172,7 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)
#pragma mark - UIBarButtonItem action
+// Method called when the "Record" button is tapped.
- (void)recordButtonToggled:(id)sender {
if (YES == _recordingData) {
[self stopRecording];
2  Routes/TARouteViewController.m
View
@@ -82,8 +82,6 @@ - (void)addCrumbOverlay {
coord.latitude = [[loc objectForKey:@"latitude"] doubleValue];
coord.longitude = [[loc objectForKey:@"longitude"] doubleValue];
- NSLog(@"coord: %f %f", coord.latitude, coord.longitude);
-
if (nil == self.crumbs) {
self.crumbs = [[CrumbPath alloc] initWithCenterCoordinate:coord];
Please sign in to comment.
Something went wrong with that request. Please try again.