Permalink
Browse files

- Added toggle/button to allow map to follow the user around

- Added toggle/button to allow map to rotate with changes in compass heading

- Changed settings on container for the MapView so it now clips the
  underlying view (which is the map itself).

- Re-sized the MapView so that is it rotates we don't see the non-map
  background; doubled the size which is probably not optimal but will
  suffice for a 1st cut

- Added a map status line which highlights when the map is following
  the user (didn't really need one for the map rotation since its
  pretty obvious what's happening).
  • Loading branch information...
1 parent 818a771 commit 5e34e56d5fa42a1d9820115448e51804c3a8a8b5 @dhmspector committed Dec 8, 2009
Showing with 225 additions and 47 deletions.
  1. +7 −2 Classes/MainViewController.h
  2. +50 −16 Classes/MainViewController.m
  3. +167 −28 MainView.xib
  4. +1 −1 SensorToy.xcodeproj/project.pbxproj
@@ -24,6 +24,7 @@
IBOutlet UISwitch *coreLocationSwitch;
IBOutlet UILabel *lastUpdateTime;
IBOutlet UILabel *whichNetwork;
+ IBOutlet UILabel *mapStatusText;
IBOutlet UIButton *showInfo;
IBOutlet MKMapView *mapView;
@@ -47,6 +48,8 @@
NSDateFormatter *dateFormatter;
BOOL loc_service_active;
+ BOOL rotateMap;
+ BOOL mapFollowsUser;
}
@@ -63,8 +66,10 @@
*/
- (IBAction)toggleCoreLocation;
-- (IBAction) showUserLocation;
-- (IBAction) toggleMapType;
+- (IBAction)showUserLocation;
+- (IBAction)toggleMapType;
- (IBAction)showInfo;
+- (IBAction)toggleMapRotation;
+- (IBAction)toggleMapFollowsUser;
@end
@@ -66,8 +66,9 @@ - (void)viewDidLoad
mapView.scrollEnabled = YES;
mapView.showsUserLocation = YES;
mapView.mapType = MKMapTypeHybrid;
- // this causes the map to follow the user around
- //[mapView.userLocation addObserver:self forKeyPath:@"location" options:0 context:NULL];
+ mapStatusText.text = @"Not following user";
+
+
/*Region and Zoom */
MKCoordinateRegion region;
@@ -249,17 +250,17 @@ - (void)locationManager:(CLLocationManager *)manager
float heading = [newHeading trueHeading];
NSString *ordinalPoint = nil;
- // we're going to use show the 16 common cardinal and intercadinal compass points; the idea is we
+ // we're going to use/show the 16 common cardinal and intercadinal compass points; the idea is we
// split the difference between intercardinal points. For example between north and east is northeast.
- // Between North and NorthEast and NorthEast and East two two more divisions, NorthNorthEast and EastNorthEast.
- // North -> East = 90 deg; North -> NorthEast and NorthEast -> East = 45deg, North -> NorthNorthEasy -- 22.5deg.
+ // Between North and NorthEast and NorthEast and East are two more divisions, NorthNorthEast and EastNorthEast.
+ // North -> East = 90 deg; North -> NorthEast and NorthEast -> East = 45deg, North -> NorthNorthEast -- 22.5deg.
//
// In order to have a smooth transition between the intercardinal points, you need to plit the distance yet again,
// making an 11.25 degree split. In essesnce you are declaring north to be 11.5 deg to the left or right of true north;
- // ditto to the other 3 cardinal points; To be able to get all of the 16 common compass points to display you need to
- // do the same for each of N, NNE, NE, ENE, E ESE, SE SSE, S, SSW, SW, WSW W, WNW, NW NNW
+ // ditto to the other 3 cardinal points; To be able to get all of the 16 common compass points to display you need to
+ // do the same for each of N, NNE, NE, ENE, E ESE, SE SSE, S, SSW, SW, WSW W, WNW, NW NNW.
- //NB North is a special case since the way we're normalizing it, it lies left of 359.99deg as well as < 11.25deg
+ //N.B.: North is a special case since the way we're normalizing it, it lies left of 359.99deg as well as < 11.25deg
if (heading > 337.5 + kOne32ndCompassDivision && heading < 359.99 || heading > 0.00 && heading < kOne32ndCompassDivision)
ordinalPoint = @"(N)";
@@ -297,18 +298,16 @@ - (void)locationManager:(CLLocationManager *)manager
else if (heading > (337.5 - kOne32ndCompassDivision) && heading < (337.5 + kOne32ndCompassDivision))
ordinalPoint = @"(NNW)";
-
+
// NSLog(@"Heading: %f", [newHeading magneticHeading]);
-
+
currentHeading.text = heading < 0 ? @" - " : [NSString stringWithFormat:@"%3.1fº %@", heading, ordinalPoint];
-
// This will rotate the map as the compass heading changes. We need to put the map inside another view for
- // to and deal with clipping regions I think for it to work sensibly, right now it spins the mapview on top
- // of the main view which is both wrong and really ugly.
-
- // [mapView setTransform:CGAffineTransformMakeRotation(-1 * newHeading.magneticHeading * 3.14159 / 180)];
-
+ // and deal with clipping regions I think for it to work sensibly. Right now it spins the mapview on top
+ // of the main view which is both wrong and really ugly.
+ if (rotateMap)
+ [mapView setTransform:CGAffineTransformMakeRotation(-1 * newHeading.magneticHeading * 3.14159 / 180)];
}
@@ -368,4 +367,39 @@ - (IBAction) toggleMapType
mapView.mapType = MKMapTypeHybrid;
}
+
+- (IBAction)toggleMapRotation
+{
+ if (rotateMap){
+ [mapView setTransform:CGAffineTransformMakeRotation(0)];
+ rotateMap = NO;
+
+ }
+ else
+ rotateMap = YES;
+ NSLog(@"Changed rotateMap to %@", rotateMap ? @"YES" : @"NO");
+
+}
+
+
+- (IBAction)toggleMapFollowsUser
+{
+ // this causes the map to follow the user around - This needs to be a toggle;
+ // if it's on, the map will literally follow the user undoing any moves/drags/zooms
+ // the user does.
+
+ mapFollowsUser = !mapFollowsUser;
+
+ if (mapFollowsUser) {
+ [mapView.userLocation addObserver:self forKeyPath:@"location" options:0 context:NULL];
+ mapStatusText.text = @"Following user";
+ }
+ else {
+ [mapView.userLocation removeObserver:self forKeyPath:@"location"];
+ mapStatusText.text = @"Not following user";
+ }
+
+ NSLog(@"Changed mapFollowsUser to %@", mapFollowsUser ? @"YES" : @"NO");
+}
+
@end
Oops, something went wrong.

0 comments on commit 5e34e56

Please sign in to comment.