Tutorial 3

From BA3 Mapping Engine Wiki
Jump to: navigation, search

Tutorial 3 - Adding Track-Up functionlity to the GPS code from Tutorial 2

In Tutorial 2 we added code so that the app can respond to GPS coordinates from the device. Here in Tutorial 3 we will add code so that Track-Up functionality is created. The idea behind Track-Up mode is to rotate the map as the vehicle changes direction.

Step 1

We need to add one new property to ViewController.h:

@property (assign) BOOL isTrackupMode;

Step 2

Modify the didUpdateToLocation function in ViewController.m so that this piece of code is added to the end of the function:

		[self.meMapViewController.meMapView setCameraOrientation:newLocation.course

This sets the camera orientation in the Mapping Engine to match the heading reported by the GPS.

Step 3

Add this function to ViewController.m:

//Turn track-up mode on or off
- (void) enableTrackupMode:(BOOL) enabled
		[self.meMapViewController setRenderMode:METrackUp];
		self.meMapView.panEnabled = NO;
		[self.meMapViewController unsetRenderMode:METrackUp];
		self.meMapView.panEnabled = YES;
	self.isTrackupMode = enabled;

This function can handle enabling an disabling of the Track-Up functionality.

Step 4

Add this line to the bottom of the viewDidLoad function in ViewController.m:

	//Turn on trackup mode
	[self enableTrackupMode:YES];

Step 4

Run the app. In the iOS Simulator menu bar, choose the Debug menu and then choose the Location item. Choose one of the options that show motion, like "Freeway Drive" or "City Bicycle Ride". Look in the console window of Xcode and you will see the speed and course changing. The map should pan to the new location so that the new location is centered on the screen and rotate the map to demonstrate Track-Up mode.

Step 5

If you get lost or wish to save yourself the typing, simply checkout tutorial3 using these commands:

git reset --hard
git checkout tutorial3

Step 6

Now we would like the add a couple of buttons over the Mapping Engine to add some basic UI functionality to the app. This is explained in Tutorial 4.

You can learn more about the Mapping Engine classes used in this tutorial in the Documentation. You can find a directory of all of the tutorials on the Main Page. If you have any questions about the BA3 Mapping Engine, any feature requests or suggestions for improving the Mapping Engine, please send them to info@ba3.us

Personal tools